I was wondering if there was a way to test if a key the user pressed is a character.
Printable View
I was wondering if there was a way to test if a key the user pressed is a character.
Do you mean as in letters a-z? Look into the isalpha() function
All characters are stored as integer codes(a char type is actually an int), so you can test what character was entered by comparing it to the integer codes for the characters you are interested in.
For instance, the characters a-z are stored as the integer codes 97-122(from an ASCII table). So, if you wanted to check whether the char entered was a lower case letter, you could do something like this:
Code:char letter;
cin>>letter;
if(letter >= 97 && letter <= 122)
cout<<"Found a lower case letter.";
http://www.cppreference.com/ascii.html <= an ASCII chart... most likely your machine is using ASCII... but I would go with the isalpha(); function found in <cstring>... it's alot easier and better for readability