Data File handling in classic c++ (much like C) -


i made following program. there mistake in bold part. value of count in output i'm getting zero. there no errors when compiled code.

#include<iostream.h> #include<conio.h> #include<fstream.h> void main() {     clrscr();     void count();     fstream file("story.txt",ios::in|ios::out);     file<<"he playing in ground. she\nis playinbg dolls.\n";     file.close();     count();     getch(); } void count() {     ifstream file("story.txt");     file.seekg(0);int count=0;     while(!file.eof())     {         char line[10];         **file.get(line,10,' ');         cout<<line<<"\n";         if(line=="he")             ++count;**     }     cout<<count;     file.close(); } 

string comparison not done through ==. merely compares address replace

if(line=="he") 

with

if(!strcmp(line, "he")) 

edit

for case insensitive

if(!strcmpi(line, "he")) 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -