Searching through text files

I had a program installed when I was younger that would save my old AIM conversations. I want to write a program that will search through them for different words. I am not really sure how to approach it, all I have so far is the reading part. the search would be a string
1
2
3
4
5
6
7
8
9
10
11
string search;
ifstream inFile;
inFile.open(test.html);
if(!inFile){
cout << "Unable to open file" << endl;
exit(1);
}
cout << "Enter word to search for: ";
getline(cin,search);
//search code goes here...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
string search;
ifstream inFile;
string line;

inFile.open(test.html);

if(!inFile){
cout << "Unable to open file" << endl;
exit(1);
}
cout << "Enter word to search for: ";
cin >>search;


size_t pos;
while(inFile.good())
  {
      getline(inFile,line); // get line from file
      pos=line.find(search); // search
      if(pos!=string::npos) // string::npos is returned if string is not found
        {
            cout <<"Found!";
            break;
        }
  }

http://www.cplusplus.com/reference/string/string/find/
Last edited on
Topic archived. No new replies allowed.