printing contents of a 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;

cin.ignore();

break;

}

}

if(!infile)

{

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

cin.ignore();

}

}

cin.ignore();

return 0;

}


Popular posts from this blog

ch11 review silberschatz operating systems concepts essentials 2nd ed