Featured
- Get link
- X
- Other Apps
Line Count program in C++ using file handling
#include<fstream.h>
#include<string.h>
#include<conio.h>
void main()
{
clrscr();
fstream f;
f.open("story.txt",ios::out);
f<<"This is a sample test for lines count \n";
f<<"This program tells how mnany lines in a file\n";
f<<"This program is a good example of file handling\n";
f.close();
char ch;
int lines=0;
f.open("story.txt",ios::in);
f.get(ch);
while(!f.eof())
{
if(ch=='\n')
lines++;
f.get(ch);
}
cout<<"count of lines->"<<lines<<endl;
f.close();
getch();
}
#include<string.h>
#include<conio.h>
void main()
{
clrscr();
fstream f;
f.open("story.txt",ios::out);
f<<"This is a sample test for lines count \n";
f<<"This program tells how mnany lines in a file\n";
f<<"This program is a good example of file handling\n";
f.close();
char ch;
int lines=0;
f.open("story.txt",ios::in);
f.get(ch);
while(!f.eof())
{
if(ch=='\n')
lines++;
f.get(ch);
}
cout<<"count of lines->"<<lines<<endl;
f.close();
getch();
}
- Get link
- X
- Other Apps
Popular Posts
C++ program to display numbers which get reversed after multiplying by 4
- Get link
- X
- Other Apps
Comments
Post a Comment