#include#include using namespace std; int main() { ofstream outfile; outfile.open("example.txt"); outfile << "This is an example of writing data to a file." << endl; outfile.close(); return 0; }
#includeThis code snippet appends the text "This is an example of appending data to a file." to the file named "example.txt". This is done by using the ios_base::app flag when opening the file, which specifies that the file should be opened in append mode. The data is written using the << operator, and the file is closed using the close() function.#include using namespace std; int main() { ofstream outfile; outfile.open("example.txt", ios_base::app); outfile << "This is an example of appending data to a file." << endl; outfile.close(); return 0; }