save data as text file

Jan 28, 2016 at 10:12am
it is possible to save the output result in c++ as a text file and use this text file to plot it in python for example.And also how we can save output data into text file?I knew how to open file
like this :
1
2
3
4
ofstream myfile;
myfile.open("result1.txt", ios::out | ios::binary | ios::trunc);
 
myfile.close();


but sofar I do not know how to save data to text file.

Thanks in advance.
Last edited on Jan 28, 2016 at 10:15am
Jan 28, 2016 at 11:34am
Use the operator>> and operator<< like so:

myfile << "Text " << 123 << " Another Text" << endl;

With streams you can easily write all kinds of data as text.
Jan 28, 2016 at 11:44am
I solved this now.
Thanks
Last edited on Jan 28, 2016 at 11:44am
Topic archived. No new replies allowed.