Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Using the ofstream class to create files and save data to the disk.
#include <fstream>
using namespace std;
ofstream outFile("data.txt");
if (outFile.is_open()) {
outFile << "Hello File!\n";
outFile << 100 << endl;
outFile.close();
}Default. Opens the file and truncates (deletes) existing content.
Use ios::app to add data to the end of an existing file.
Always check if the file opened successfully. It might fail if the disk is full, the folder is read-only, or the file is locked by another app.