To append text to an existing file, we include the std::ios::app flag inside the file stream constructor:
#include <fstream> int main() //from w w w . jav a 2 s .c om { std::fstream fs{ "myoutputfile.txt", std::ios::app }; fs << "This is appended text" << '\n'; fs << "This is also an appended text." << '\n'; }