If no match is found, .find() returns value string::npos (not -1) which is what the return value needs to be tested against. Also the return type of .find() is size_t and not int. See http://www.cplusplus.com/reference/string/string/find/