Master C++ with Real-time Projects and Kickstart Your Career Start Now!!
Program 1
#include<iostream>
#include<string>
#include<fstream>
#define clrscr() system("cls");
using namespace std;
int main()
{
// open file in read mode
fstream fin;
clrscr();
fin.open("g://cppdata/student.txt",ios::in);
if(fin.is_open()) // check file open
{
string st;
int i=0;
while(getline(fin,st)) // till file is not reach to end
{
cout<<st<<"\n";
i++;
}
cout<<"\n Total lines :"<<i;
}
else
cout<<"\nfile error";
return 0;
}