I know that I can check if a "word" is all letters by:
bool checkAlpha(string str){
bool retVal;
for(int i = 0; i < str.size(); i++){
if(isalpha(str[i]) == 0){
retVal = true;
cout << "Input must only contain letters\n";
break;
}
else{
retVal = false;
cout << "all good\n";
}
}
return retVal;
}
Because of how I use the function return value, I need it to return TRUE if it is NOT all letters, and FALSE if it IS all letters. There's probably an easier way to do this but I just started C++ so this works for my current purpose.
My question is how do I check if a string is multiple "words"? When it reaches a space the function (correctly) says the space is not an alpha and tells me the input must only be letters. I tried doing
if((isalpha(str[i]) != 0) || (str[i] == " "))
and changing the "if" to return false (input only letters & space) and "else" to return true, but when I tried this I got a compiler error:
ISO C++ forbids comparison between pointer and integer [ -fpermissive]
So what can I do to get that a string of user input is only letters or space? (Preferably the simplest method)