Write Stringstream in fstream ...

  • Thread starter =?ISO-8859-1?Q?Konrad_M=FChler?=
  • Start date
?

=?ISO-8859-1?Q?Konrad_M=FChler?=

Hi,

I have a stringstream and want to write it 1:1 in a file.
Using this doesn't work:

stringstream myStream;
....
ofstream myFile(filename);
myFile<< myStream;
myFileclose();


I don't want to parse the stream line by line. Is there an easy way to
write the hole stream all at once in the file?

Thanks
Konrad
 
V

Victor Bazarov

Konrad said:
I have a stringstream and want to write it 1:1 in a file.
Using this doesn't work:

stringstream myStream;
...
ofstream myFile(filename);
myFile<< myStream;

Have you tried

myFile << myStream.str();
myFileclose();


I don't want to parse the stream line by line. Is there an easy way to
write the hole stream all at once in the file?

I am not sure what "easy" means.

V
 
P

Pete Becker

Hi,

I have a stringstream and want to write it 1:1 in a file.
Using this doesn't work:

stringstream myStream;
...
ofstream myFile(filename);
myFile<< myStream;
myFileclose();

myFile << myStream.rdbuf();

This works for all types of streams.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top