Oh okay. You're using getline properly. When you wrote the example in the first post it made me think that record.number would be of type int or double.
Again, use [ code ] tags [ /code ] when posting code, please.
Lets see. You want to input a number, stored inside a char variable. I believe it would make more sense to store it into an unsigned int (~4 billion as the upper limit), which should be more than enough for unique record numbers in your program.
It's beneficial to store it in an int in the event that you want to compare it with other numbers or do arithmetic with it in the future.
The reason case1 did not work for you is because cin.fail is only set when reading something that should be a char into an int, double, etc. Otherwise it can be interpreted as a char anyway. So if you mace record::number an unsigned int, using the cin.fail() technique will work.
Now, in case 2 you have a char array that you want to make sure are all characters. You have a couple options depending on which characters you consider valid for a record category.
Do you want a character to be a-z, A-Z only,
or do you want a character to be a-Z, A-Z, !-), special characters, etc, as well?
If the former, you can use the function
isalpha
on all the characters in
category
.
http://www.cplusplus.com/reference/cctype/isalpha/?kw=isalpha
isalpha
will return true only if a character is alphabetic.
Note that this function only works on individual characters, not the entire array, so you must call it against each character in category[].
if the latter, you can use
isdigit
, and check to see if it is
not a digit instead.
The same thing applies here as it did with
isalpha
, it must be called against every character in category[]