In C++, you can concatenate std::string
objects using +
, or append to a string stream.
In both C and C++ you have access to formatted output, which I think is preferred here, because the whole code fits neatly on a single line:
sprintf(buffer, "%s:%s:%s:%s", amount, cardNum, name, expiration);