Hi everyone,
Im trying to solve this question:
write a C++ program to find a given word in a file. It should display all the line numbers where the word occurs.
this is the code that i did so far, the problem is it wont display all the right line number, it only displays "1" :( I hope that you guys can help me fix it up.
#include <iostream>
#include <conio.h>
#include <fstream>
using namespace std;
int main()
{
string s1;
ifstream in ("file.txt");
int lines = 0;
cout << "Enter your search string: " <<endl;
cin >> s1;
in.seekg(0,ios::beg);
lines ++;
cout<<"The string occured at lines: " << lines<<endl;
in.close();
getch();
return 0;
}
Thanks in advance,
itchap