开发者

C++, Accept lowercase and uppercase letters in a variable

I want to allow the user to use lowercase or uppercase letters giving the value to the char type variable... Any help?开发者_如何学Go?


Err, do you mean something like (where getAChar() is whatever method you're using to get the character):

int ch = getAChar();
while (!isalpha (ch))
    ch = getAChar();

Alternatively, if you want to check that a user enters only alphas. You can get a string with:

cin >> myString;

Checking for alphas is as simple as:

char *cstr = myString.c_str();
for (int i = 0; i < myString.length(); i++)
    if (!isalpha (*cstr++))
        return false;
return true;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜