Reading a File in C++

C++ Program to read the contents of a file.

Source code :


#include <iostream>
#include <fstream>

using namespace std;

int main () {
    
  ifstream file;
  string line;
  
  file.open ("sample.txt");
  
  if (file.is_open())
  {
    while ( getline(file,line) )
    {
      cout << line << endl;
    }
    file.close();
  }
  return 0;
}

Output :

Aroliant is a team on tech, that runs on the Web for the past few years.
We are a team of techies indulged in Product Oriented Development, Created super cool products that works across all the industrial leading platforms Android, Chrome and the Web.
Our applications are designed with cross-platform compatibility. We have a very strong site ecosystem. We love Open Source and the Web.

Notes :

sample.txt

Aroliant is a team on tech, that runs on the Web for the past few years.
We are a team of techies indulged in Product Oriented Development, Created super cool products that works across all the industrial leading platforms Android, Chrome and the Web.
Our applications are designed with cross-platform compatibility. We have a very strong site ecosystem. We love Open Source and the Web.

Output :


                

Comments :