I have a byte data source defined like this:
char * data;
unsigned int dataSize;
dataSize
is non zero and often quite large (megabytes)
The following code works:
std::string str(data, dataSize);
std::istringstream stream(str);
char firstByte = stream.peek();
stream.eof()
is false, and firstByte is 1
, which is correct
The following code does not work:
std::strstream stream(data, dataSize);
char firstByte = stream.peek();
stream.eof()
is true, and firstByte is -1
, which is incorrect
I know that strstream is deprecated, but in this case it avoids allocating and copying twice the incoming data, which is nice. But why are peek and eof not working ?
EDIT : If I replace std::strstream
by std::istrstream
, this works fine. And this is OK as I'm in fact only reading from data.
But why std::strstream is not working in that case? I'm just curious.