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;
}
#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;
}