Stringstream?

I need a better understanding of how stringstream works. What I am trying to do is write a code that sends data to an html page, but I'm not sure if it works the same as writing to an output file because my html page shows up blank.

1
2
3
4
5
6
7
stringstream ss;
ofstream oFile;
oFile.open ("file.html");

ss << "Hello World/n";

oFile.close();
ss and oFile are two different streams. Why do you think changing ss would have any effect on oFile?
I should probably mention that my ofstream is in a private member function
1
2
3
4
5
6
7
class myClass
{
     Private:
               string filename;
               ofstream oFile;

};
This does not matter. ss and oFile are different streams and have no relation to each other. So if you want outpu something to file opened by oFile, you should output it to oFile.
If you want to write the content of stringstream ss to ofstream oFile you could do:
1
2
ss << "Hello World/n";
oFile << ss.str();

But the stringstream is not really needed here. You can just write to oFile directly:
 
oFile << "Hello World/n";
Oh yes I understand now, I guess I was overthinking it since classes are new concept to me. Thank you for your help.
Topic archived. No new replies allowed.