I want to print an error message if the user's input string does not match what is intended. However, std::string::npos does not print it.
void AdvisorBot::printHelpCMD() {
std::string prod ("prod");
std::string min ("min");
std::string max ("max");
std::string checkInput("prod min max");
std::cout << "\nEnter the command you need help with e.g <prod>: " << std::endl;
std::string cmd;
std::getline(std::cin, cmd); //takes input and store into string cmd
if (cmd == prod) {
std::cout << "\nThis command lists all the available products on the exchange.\n" << std::endl;
}
if (cmd.find(checkInput) != std::string::npos) { //to loop over inputted strings and check if matches above NOT WORKING
std::cout << "\nCommand does not exist\n" << std::endl;
}
==.==, the string "Commad does not exist" is printed even when the user input is correct. For example, if user types prod, the error appearsifis backwards. If the returned value equalsstd::string::nposthen there was no match.prod min max.checkInput.find(cmd)godbolt.org/z/d7v98nx5M