Need a project done?

C++ Programming Developer

Search This Blog

Read from a file C++


Program to read from a file in C++.
#include <iostream>
#include <fstream>

using namespace std;

int main(){
ifstream infile;
infile.open("rehan.txt");//rehan.txt must exist in the directory in which you've created your project.

char a[40];
while (infile){
infile.getline(a,40,'\n');
cout << a << endl;
}
infile.close();
return 0;
}
See also:

Write in file C++


No comments:

Post a Comment

"Don't let anyone ever make you feel like you don't deserve what you want."