Hi,
i have the following problem:
i have a vector of chars
and a string.
i want to make 1 array of chars, which will contains first the string and then the vector (i want to send all of it as 1 array to a server.., so i need to send an array of chars)
i tried everything like c_str() on the string.. it doesn't work
my string is like 40 chars long and the array i get from using c_str() has only 8 chars. it cuts off all the other chars.
i did manage to put the vector in an array.
but converting the string into array of chars.. and then combining them both to 1 array - simply everything i tried didn't work
You might have difficulty if your string contains any null characters, but it should still work just fine as long as you're mindful of that possibility:
1 2 3 4 5 6 7
vector<char> vec = /*...*/;
string str = /*...*/;
char* p = newchar[vec.size() + str.size()]; // assuming you don't need null termination
std::copy( str.begin(), str.end(), p );
std::copy( vec.begin(), vec.end(), p + str.size() );