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

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
I don't understand what you mean.

You can write them in like anything else, just use operator << like you are.
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
Topic archived. No new replies allowed.