Hey im validating a string.
string getString(string q)
{
string input;
do
{
cout << q.c_str() << endl;
cin >> input;
} while (!isalpha(input));
return input;
}
When using while(!isalpha(input)); input gives that error.
Can anyone help me with this?
The other answer describes what the problem is, but here’s a solution that makes use of algorithms from the standard library instead of writing your own (example requires C++11)
The above function will return true only if all characters in the string are alphabetic. If you only want to disallow numeric characters, I’d use a slightly different function.
or
Use these functions to validate the input that you receive from the user.
If you can’t use C++11 features, the functions can be modified to use
std::find_ifinstead, and compare the return value offind_iftos.end()to determine success / failure.