im currently coding a http uploader. everything went ok for now but i had a problem with data which has null characters. the data was truncated. my vb6 version works flawlessly. what i do is something like below (ported from vb6 code):
char *szBuffer
std::string is perfectly capable of holding null characters.
The problem is that C-style strings and string literals use it to mark the end of the string. So if you want to use null characters, you need to determine the end of the string some other way.
Typically, you can do this with append() instead of using the operators. append allows you to explicitly state the length
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13
std::string foo;
// a char array with 9 characters, 2 of which are null
char example[10] = "123""\0""567""\0""9";
foo += example; // BAD will not work. Will only add "123" and will stop at the null
foo.append(example,9); // OK, works just fine
// say you want to append a null:
foo += "\0"; // BAD does not append anything
foo.append("\0",1); // OK, appends a null
EDIT:
Note that you can use the +, += operators when dealing with other std::strings because they don't use the null to mark the end of the string.
Just be sure not to use the operators when working with string literals or char arrays:
1 2 3 4 5
std::string foo = "asljdkflsd";
std::string bar = /*contains some null characters */;
foo += bar; // OK, even if bar contains nulls