cplus plus fstream contents of file

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main(){
int linecount=0;
string filename;
fstream infile;

cout<<"enter a filename :"<<endl;
cin>>filename;
 

infile.open(filename, ios::in);

if (infile)



{
 
string line;



getline (infile, line);
 
while (infile)



{

cout<<line<<endl;

getline(infile, line);

linecount++;
 
if ((linecount=10) && (infile))



{
 
cout<<"first ten records printed"<<endl;

break;



}

}
 
if(!infile)



{
 
cout<<"entire file printed"<<endl;



}

}

}

 

Popular posts from this blog

ch11 review silberschatz operating systems concepts essentials 2nd ed