Friday, 22 January 2016

C Plus Plus Program to Illustrate Reading of Data from a File -- cppexamples

Leave a Comment
Questions:

C Plus Plus Program to Illustrate Reading of Data from a File

Explanation:

This C Program illustrates reading of data from a file. The program opens a file which is present. Once the file opens successfully, it uses ifstream library call to read the content.

ifstream: This data type represents the input file stream and is used to read information from files.



Code:

#include<iostream>
#include<fstream>
#include<string>
using namespace std;
void main() {
       ifstream file("Temp.txt");//creating txt file
       while (file) {
              string temp;
              getline(file, temp);
              cout << temp << endl;
       }
       file.close();

}

Output:


Related Articles :

C Plus Plus Program to Create a File & Store Information
If You Enjoyed This, Take 5 Seconds To Share It