1234567891011121314151617181920212223242526272829303132333435
void FindWord() { string str = "This is a string of words to search with the search function"; cout << str << endl; cout << "\nEnter a word to find from the string above" << endl; string strToFind; getline(cin, strToFind); string::iterator it = str.begin(); string compare = strToFind; size_t pos = str.find(strToFind); while(it != str.end()) { str.find(strToFind); if(compare == strToFind) { cout << "Found \"" << strToFind << "\"" << " at position " << pos << endl; break; } else { cout << "Did not find \"" << strToFind << "\"" << endl; break; } *it++; } }
str.find(strToFind);