mardi 1 décembre 2015

How would I have string validate just the ENTER key being hit?

void Game::validate(string& str1)
{
    bool exit = false;
    int strLength = str1.length();
    while (exit == false)
    {
        for (int i = 0; i < strLength; i++)
        {
            if(!isalpha(str1[i]) || isspace(str1[i])) //|| str1.empty())//?
            {
                cout << "Not a valid name, please try again: " << endl;
                getline(cin, str1);
            }
            else if(isalpha(str1[i]))
            {
                exit = true;
            }
        }
    }

I am passing down a string,i need to output the error message if the user hits the Enter key only*. Ive tried using '\n' but isspace should take care of that(which it dosent). When i run the program and hit ENTER only, it freezes...whats wrong with it??? All other validation works except the ENTER key

Blockquote

Aucun commentaire:

Enregistrer un commentaire