C
coomberjones
I have a few std::strings that I am using to store raw binary data,
each of which may very well include null bytes at any point or
points. I want to slap them together into a single string, so I tried
a std:
stringstream:
std:
stringstream oss;
oss << x << y << z;
std::string result ( oss.str() );
The result shows that feeding the ostringstream with a string just
takes the string's data up to (and not including) the first null
character.
Stroustrop's book is vague about what should happen (at least in the
sole reference I could find); it merely says "The << operator writes a
string to an ostream".
Obviously I could just concatenate the strings using the + operator.
But I'm wondering - is there some other kind of stream that is
supposed to be used for the purpose I want? Or some stream
manipulator?
And I'm also wondering whether the observed behavior is correct in the
first place. Like I said, the sole reference I could find is vague,
but I would lean towards my original assumption when interpreting it.
And I certainly hope the behavior is not different from compiler to
compiler!
Thanks.
each of which may very well include null bytes at any point or
points. I want to slap them together into a single string, so I tried
a std:
std:
oss << x << y << z;
std::string result ( oss.str() );
The result shows that feeding the ostringstream with a string just
takes the string's data up to (and not including) the first null
character.
Stroustrop's book is vague about what should happen (at least in the
sole reference I could find); it merely says "The << operator writes a
string to an ostream".
Obviously I could just concatenate the strings using the + operator.
But I'm wondering - is there some other kind of stream that is
supposed to be used for the purpose I want? Or some stream
manipulator?
And I'm also wondering whether the observed behavior is correct in the
first place. Like I said, the sole reference I could find is vague,
but I would lean towards my original assumption when interpreting it.
And I certainly hope the behavior is not different from compiler to
compiler!
Thanks.