C++ ЗАПИСЬ В ФАЙЛ

cd ~/

nano file-writer.cpp

#include 
#include 
using namespace std;

int main () {
  ofstream myfile ("example.txt");
  if (myfile.is_open())
  {
    myfile << "This is a line.\n";
    myfile << "This is another line.\n";
    myfile.close();
  }
  else cout << "Unable to open file";
  return 0;
}

sudo g++ -Wall -o file-writer file-writer.cpp

./file-writer