Hey im getting this error when trying to validate a string. Basically i want the game to not continue until the user enters a valid name. John, Mary etc.. and not a number 123434 etc…
Here is my code:
string input1 ="What is your name ?\n";
string name = getString(input1);//The error is in the getString.
bool getString(string str)
{
for (int i = 0; i < str.size(); i++)
{
if (isdigit(str[i]))
return false;
}
return true;
}
You can’t cast a bool to a string or convert a
booltostring, there is noimplicit conversion. Perhaps you really want to return a string. I’m not sure as you name your functiongetString, yet you return abool.Unless you have a list of names handy and compare the input against the database, file etc.. comparing the input can be difficult.
What if the user enters Dsjdksdksdksdskd?
To help/answer your question: