How Can I Append Contents to a File
Below we append contents to a file in C++
#include <fstream> #include <iostream> #include <string> using namespace std; int main() { string contents= "\nThis is a new line"; contents.append("\n\nThis is a new paragraph"); ofstream writer("file1.txt", ios::app); if (!writer) { cout << "There was an error opening file for output" << endl; return -1; } writer<< contents << endl; writer.close(); return 0; }