how to write different types (string, int, double, etc..) into each line of a file ?

May 19, 2012 at 7:51am
Hello,

I have the following question. How can I write a line consist of different data types (string, double, int, etc...) into a file ?. Here are some lines of the code I wrote and m_totalGeneratedPackets is an int :


1
2
3
4
ofstream resultsFile;
resultsFile.open ("interstitial_results.txt", ios::out);
resultsFile << "Total Number of generated packets in nodes is : "<<m_totalGeneratedPackets<<"\n";


Thanks
May 19, 2012 at 8:06am
I don't understand what you mean.

You can write them in like anything else, just use operator << like you are.
May 19, 2012 at 8:19am
Do not include in an output stream new line character and all you data will be in one line.:)
Fpr example

1
2
3
std::string s( "The value of number x is " );
double x = 10.0;
std::cout << s << x;
Last edited on May 19, 2012 at 8:20am
Topic archived. No new replies allowed.