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