To write data from ostringstream
to a ofstream
, I have to write something like this:
std::ostringstream ss;
myFile<<ss.str();
on the other hand, if I use the stringstream
I can access directly the buffer:
std::stringstream ss;
myFile<<ss.rdbuf();
The problem is that ostringstream::str()
makes a copy of the string which is kind of bad because in my program there are very huge strings, so stringstream
should be better because I can access directly the buffer for reading. And people here say that we should use ostringstream
over the stringstream
if we deal only with output operations. I can't simply use a string because I am inserting various type of data. So could someone give me an advice on how to deal with this?