My program should look for a word in a text file, and if it finds that word, print / display the entire line. Example:
employee name date joined position project annual salary
tom jones 1/13/2011 accountant pricing 55000
Susan lee 2/5/2007 Manager policy 70,000
The user enters the search word:
accountant
The program searches for text for accountant . When he finds this, he returns the following:
employee name date joined position project annual salary
tom jones 1/13/2011 accountant pricing 55000
This is the code I came up with, but it does not work.
void KeyWord(ifstream &FileSearch) { string letters; int position =-1; string line; ifstream readSearch; cout<<"enter search word "; cin>>letters; "\n"; FileSearch.open("employee"); if(FileSearch.is_open()) { while(getline(FileSearch, line)) { FileSearch>>line; cout<<line<<endl; position=line.find(letters,position+1); if(position==string::npos); if(FileSearch.eof()) break; cout<<line<<endl; } } cout<<"Cant find"<<letters<<endl; }
c ++ string-matching io
Darius
source share