Answers for "file.get c++"

C++
2

c++ get file content

#include <fstream>
#include <string>

int main(int argc, char** argv)
{

  std::ifstream ifs("myfile.txt");
  std::string content( (std::istreambuf_iterator<char>(ifs) ),
                       (std::istreambuf_iterator<char>()    ) );

  return 0;
}
Posted by: Guest on August-01-2021
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