Answers for "cpp write to file with fd"

C++
30

c++ writing to file

// basic file operations
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile;
  myfile.open ("example.txt");
  myfile << "Writing this to a file.\n";
  myfile.close();
  return 0;
}
Posted by: Guest on November-09-2019
0

c++ write to file in directory

ofstream myFile("/Your/File/Path/YourFilename.txt");//writing to this file
if (myFile.is_open())
{
   myFile << "This is a line." << "\n";
   myFile << "This is another line." << "\n";
   myFile.close();
}
else
   std::cout << "Unable to open file";
Posted by: Guest on April-13-2021

Browse Popular Code Answers by Language