c++ write to file
#include <iostream>
#include <fstream>
int main() {
// Open a file named "example.txt" in write mode
std::ofstream outputFile("example.txt");
if (outputFile.is_open()) {
// Write to the file using the ofstream object
outputFile << "Writing this text to the file.\n";
outputFile << "Adding another line here.\n";
// Close the file
outputFile.close();
std::cout << "Successfully wrote to the file.\n";
} else {
std::cout << "Unable to open the file.\n";
}
return 0;
}