const char* concatenation
If you are using C++, why don't you use std::string
instead of C-style strings?
std::string one="Hello";
std::string two="World";
std::string three= one+two;
If you need to pass this string to a C-function, simply pass three.c_str()
In your example one and two are char pointers, pointing to char constants. You cannot change the char constants pointed to by these pointers. So anything like:
strcat(one,two); // append string two to string one.
will not work. Instead you should have a separate variable(char array) to hold the result. Something like this:
char result[100]; // array to hold the result.
strcpy(result,one); // copy string one into the result.
strcat(result,two); // append string two to the result.
The C way:
char buf[100];
strcpy(buf, one);
strcat(buf, two);
The C++ way:
std::string buf(one);
buf.append(two);
The compile-time way:
#define one "hello "
#define two "world"
#define concat(first, second) first second
const char* buf = concat(one, two);