strings and char
I have two c type char arrays that I want to add together (with a space in between) and put into a cpp string. I am assuming da dis is the best way 2 do it.
I appreciate that stirng can be added but not like this.
char n1 = "Bill";
char n2 = "Stone"
string str = n2 + " " + n1;
Anyone have any ideas for me plz?
Use the strcat function.
Or you can use:
sprintf(fullbuffer, "%s %s", n2, n1);
Just make sure you have a big enough buffer.
Or, if you want to actually use C++ style strings from C style array strings:
string str = string(n1) + " " + string(n2);
stringstream strs << n1 << " " << n2;
string str = strs.str();
Lol, you guys taking the easy way out ! :(
Originally Posted by matsp
Would that be classed as type casting the char *'s??????
That would be creating a temporary string out of a char* using the respective constructor.