ifstream FileSearch;
FileSearch.open("employee");
if(FileSearch.is_open())
{string letters;// search word would be store here
string row; ??stores entire row as string
while(1)
{
cout<<"Enter search key ";// get word to search for
getline(cin,letters);
getline(FileRead, employee);
if(FileRead.eof())
break;
//search for word
while((startP = employee.find(letters, startP))!=string::npos)
cout<<row<<endl; //diplay entire row
}
}
else{
cout<<"can not open a file 2"<<endl;
}
whiletrue {
Get the search key from the user
if the key is blank then break
findKeyInFile(search key);
}
void findKeyInFile(const string &key)
{
open the file
while (not at end of file) {
read a line from the file
if (the key is in the line just read) {
output the line
}
}
close the file
}
almost but no cigar..any suggestions..it compiles but doesn't actually search the word..or maybe it does, but doesn't give me expected results.. Not sure what is wrong..I just know its not giving me a result
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
string quote = "If it walks like a duck, ""and quacks like a duck, \n""then it just may be a duck - Reuther";
int position = -1;
while(1)
{
position = quote.find("duck", position+1);
if(position == string::npos)
break;
cout<<position<<endl;
}
return 0;
}