Horje
c++ open file Code Example
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;
}
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;
}
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;
}




Cpp

Related
3d vector c++ resize Code Example 3d vector c++ resize Code Example
include pdf file in latex Code Example include pdf file in latex Code Example
c++ how to read from a file Code Example c++ how to read from a file Code Example
multiline comment in C++ Code Example multiline comment in C++ Code Example
prints out the elements in the array c++ Code Example prints out the elements in the array c++ Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
10