Im trying to have the boolean found_word to return true if it finds the word/character and false if it doesn’t, but it returns true ALWAYS, no matter what I write in the text. The loop itself works, already tried that. IOStream and string are included.
while(timestorun){
found_word = text.find("khgdawjugfdjhawbdjkhsadgawkdsa");
if(found_word){
cout << "FOUND!!!" << endl;
}
else if(!found_word){
cout << "Found problem!!!!!"<< endl;
}
timestorun--;
}
Any suggestions?
You’re supposed to compare with
npos.finddoesn’t return a boolean value.0, which isfalse, would only be returned if the substring was found at index0.Also, your second condition is redundant – if
found_wordisfalse, I personally guarantee!found_wordwill betrue.