Skip to main content

Featured

functions in Python

File handling Program to count words in C++

#include<fstream.h>
#include<string.h>
#include<conio.h>
void main()
{
fstream f;
f.open("story.txt",ios::out);
f<<"This is a story of a boy. This is also a moral story. Is this a good story? Yes, this is a good story";
f.close();
char ch[10];
int count=0;
f.open("story.txt",ios::in);
f>>ch;
while(!f.eof())
{
if(strcmp(ch,"this")==0||strcmp(ch,"This")==0)
count++;
f>>ch;
}
cout<<count;
f.close();
getch();
}

//The above program gives output 4

Comments

Popular Posts