/ Published in: C++
Expand |
Embed | Plain Text
#include <iostream> #include <fstream> //necessary to use file streams int main (int argc, char * const argv[]) { std::ofstream fout; //creating new output stream without assigning a file fout.open("output.txt"); //opening a new file in which we will save the data int num = 1500; //a number to save char name[] = "John Doe"; //we could use a 'string' instead of 'char' //using the ''<<' operator we save the data we want fout << "Here is a number: " << num << "n"; fout << "Now here is a string: " << name << "n"; /* * The 'flush()' function synchonized the file with the stream buffer * In essense all data in the stream buffer that have not been written yet in the file * are now written. This a good way to update the file without using the 'close()' function. * * Here of course it holds no meaning as it is followed by 'close()' */ fout.flush(); fout.close(); return 0; }
You need to login to post a comment.
