Answers for "*FILE cpp"

C++
17

c++ files

// 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
1

file c++

#include <iostream>
#include <string>
#include <fstream> //write and read
//#include <ifstream> //read
//#include <ofstream> //write

int main () {
  std::string line;
  std::ofstream myfileWrite;
  std::ifstream myfileRead;
  myfileWrite.open("example.txt");
  myfileRead.open("example.txt");
  myfileWrite << "Writing this to a file.\n";
  while (getline(myfileRead,line)){
    std::cout << line << '\n';
  }
  myfileWrite.close();
  myfileRead.close();
  return 0;
}
Posted by: Guest on February-27-2021

Browse Popular Code Answers by Language