Writing stringstream contents into ofstream
If you are using std::ostringstream
and wondering why nothing get written with ss.rdbuf()
then use .str()
function.
outFile << oStream.str();
You can do this, which doesn't need to create the string. It makes the output stream read out the contents of the stream on the right side (usable with any streams).
outFile << ss.rdbuf();
When passing a stringstream rdbuf to a stream newlines are not translated. The input text can contain \n
so find replace won't work. The old code wrote to an fstream and switching it to a stringstream losses the endl translation.