Archived

This topic is now archived and is closed to further replies.

funky std::stringstream problem

This topic is 5530 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a function that huffman compresses one stream to another: void HuffmanCompress(std::istream& istrm, std::ostream& ostrm); If the output stream is a file, it all performs as it should:
  
std::ofstream ofile;
ofile.open("output.dat", std::ios::binary);
HuffmanCompress(someother_stream, ofile);
  
If the output stream is a std::stringstream, however, it doesnt actually write anything to it:
  
std::stringstream str;
HuffmanCompress(someother_stream, str);
  
Inside HuffmanCompress() i just use the istream::read and ostream::write() member functions - the code is pretty complicated so i wont bother with the details. Anyway, my question is am i missing some important difference between file streams and string streams that would cause this effect? I''ve tried std::strstream (yuck) instead of a stringstream, but that doesnt work either.

Share this post


Link to post
Share on other sites
quote:
Original post by Stoffel
We need the declaration of the function. I believe it should be:
void HuffmanCompress (const std::istream &in, std::ostream &out);


It was in my second sentance of my original post. Here it is again:

void HuffmanCompress(std::istream& istrm, std::ostream& ostrm);

At any rate, you cant have a const std::istream& and expect to call istream::read() on it anyway - its not a const member function.

Share this post


Link to post
Share on other sites
Ah ha! Found the problem. At one point in my code i was seekp()''ing ahead of the eof marker, which by the looks of it is allowed with files but not with stringstreams

Share this post


Link to post
Share on other sites