c++ - vector<char> with zeros to string -
i have
vector<char> sectiondata;
and see content.i seek following
string sectiondatastr = string(sectiondata.begin(),sectiondata.end());
but part of sectiondata presented in string,since sectiondata contains zeros.what can do,if case want read entire info string?
i can`t utilize std::cout thanks
your problem doesn't exist. here's simple demonstration:
#include <string> #include <iostream> int main() { std::cout << std::string { 'a', '\0', 'b', '\0', 'c' } << std::endl; }
now inspect output:
class="lang-none prettyprint-override">$ ./a.out | hexdump -c 00000000 61 00 62 00 63 0a
## \0 b \0 c \n
as can see, it's there.
alternatively (following edit):
#include <cstdio> std::fwrite(sectiondatastr.data(), sectiondatastr.size(), stdout);
c++ string vector
No comments:
Post a Comment