J
jeremie fouche
Hi
I would like to know if this is valid to embed binary data (which can
contain '\0') in a std::string. As I'm in a code review, I suggested
to change this to std::vector<char>, but the dev guys told me they
tested and it was OK.
I tested with MSVC 2005 and Mingw-gcc4.4.0 and it was fine. But I'ms
still not sure about this. I'm afraid that the '\0' char could
terminate the string in some (?) methods.
Here is the code I tested :
#include <string>
#include <iostream>
int main(void)
{
std::string s;
s.push_back(0);
s += "sdfsdf\0sdqsd";
std::cout << s.length(); // 12
std::string s2 = s;
std::cout << s2.length(); // 12
return 0;
}
What is your point of view ?
Thanks
I would like to know if this is valid to embed binary data (which can
contain '\0') in a std::string. As I'm in a code review, I suggested
to change this to std::vector<char>, but the dev guys told me they
tested and it was OK.
I tested with MSVC 2005 and Mingw-gcc4.4.0 and it was fine. But I'ms
still not sure about this. I'm afraid that the '\0' char could
terminate the string in some (?) methods.
Here is the code I tested :
#include <string>
#include <iostream>
int main(void)
{
std::string s;
s.push_back(0);
s += "sdfsdf\0sdqsd";
std::cout << s.length(); // 12
std::string s2 = s;
std::cout << s2.length(); // 12
return 0;
}
What is your point of view ?
Thanks