I need to concatenate two const chars like these:
const char *one = \"Hello \";
const char *two = \"World\";
How might I go about doing tha
One more example:
// calculate the required buffer size (also accounting for the null terminator):
int bufferSize = strlen(one) + strlen(two) + 1;
// allocate enough memory for the concatenated string:
char* concatString = new char[ bufferSize ];
// copy strings one and two over to the new buffer:
strcpy( concatString, one );
strcat( concatString, two );
...
// delete buffer:
delete[] concatString;
But unless you specifically don't want or can't use the C++ standard library, using std::string
is probably safer.