Answers for "all ways to open files in windows c++"

C++
2

file open cpp

#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile;
  myfile.open ("file.txt");
  myfile << "Writing to a file.\n";
  myfile.close();
  return 0;
}
Posted by: Guest on February-08-2021
0

c++ open file

// Reading a file

#include <iostream>
#include <fstream>
#include <string>

int main() 
{
    std::string line;

    std::ifstream file("example.txt");
    if(file.is_open())
    {
        while(getline(file, line))
        {
            std::cout << line << '\n';
        }
        file.close();
    }
    else std::cout << "Unable to open file";

    return 0;
}
Posted by: Guest on December-21-2021

Code answers related to "all ways to open files in windows c++"

Browse Popular Code Answers by Language