Skip to main content

Featured

functions in Python

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();
}

Comments

Popular Posts