Data file handling

i have created a report card in c++. the program does not save the data on closing it. kindly help me.
You need to put your code in an int main() function. After that, you need some code. I suggest using an ofstream object. You can also use the "flush" command to save.

Example:
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

int main()
{
ofstream fout("myfile.txt"); //Opens myfile.txt

fout << "some text" << endl; //Outputs something to the file
fout.flush(); // Writes to the file (saving)
fout.close(); // Closes the file
return 0;
}


Normally fout.close() should be all that you need, but flushing helps in some situations. I don't know what your code looks like but it could be one of those situations.

Does this help? Let us know.
Last edited on
Topic archived. No new replies allowed.