Hi i have been 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.
i did this code:
i just have problems in interpreting this part to code:
if(//String in file), hope that someone can help me fix it.
thanks
carly
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:
Code:
#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
Comment