Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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 << '
';
        }
        file.close();
    }
    else std::cout << "Unable to open file";

    return 0;
}
Comment

file open cpp

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

int main () {
  ofstream myfile;
  myfile.open ("file.txt");
  myfile << "Writing to a file.
";
  myfile.close();
  return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: max element in array c++ stl 
Cpp :: min heap and max heap using priority queue 
Cpp :: c++ call method in same class 
Cpp :: string to long integer c++ 
Cpp :: find max value in array c++ 
Cpp :: cpp multidimensional vector 
Cpp :: c++ segmented sieve 
Cpp :: not in c++ 
Cpp :: initialize an array in c++ 
Cpp :: when was c++ created 
Cpp :: c++ Program for Sum of the digits of a given number 
Cpp :: set was not declared in this scope 
Cpp :: coordinate in 1d array 
Cpp :: size of pointer array 
Cpp :: calloc c++ 
Cpp :: joins in mysql use sequelize 
Cpp :: c++ string to char array 
Cpp :: time of a loop in c++ 
Cpp :: concat two vectors c++ 
Cpp :: opencv open image c++ 
Cpp :: long to string cpp 
Cpp :: iterate through map c++ 
Cpp :: string split by space c++ 
Cpp :: how to play sounds in c++ 
Cpp :: c++ contains 
Cpp :: intersection.cpp 
Cpp :: Max element in an array with the index in c++ 
Cpp :: C++ Increment and Decrement 
Cpp :: how to generate number in c++ 
Cpp :: c++ region 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =