Write a C++ program to find a given word in a file. It should display all the line numbers where the word occurs.
i did this code:
Expand|Select|Wrap|Line Numbers
- #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;
- while(!in.eof())
- {
- in.seekg(0,ios::beg);
- lines ++;
- if(//String in file)
- {
- cout<<"The string occured at lines: " << lines<<endl;
- }
- }
- in.close();
- getch();
- return 0;
- }
if(//String in file), hope that someone can help me fix it.
thanks
carly