Ahmad Farid Ahmad Farid - 2 months ago 18
C++ Question

How to append text to a text file in C++?

How to append text to a text file in C++? Create new if does not exist and append if exist.

Answer
#include <fstream>

int main() {  
  std::ofstream outfile;

  outfile.open("test.txt", std::ios_base::app);
  outfile << "Data"; 
  return 0;
}
Comments