There is nothing in the standard C++ set of functionality that will "stop" a user from entering random digits when asked for a string. You will have to write some code to determine if the input is valid - for example check each character of the string to see if it's digits or not. Depending on the exact criteria, "no digits" or "must not be ONLY digits" or whatever, you will have to come up with the code to check it.
Useful functionality is isdigit
, which requires #include <cctype>
. There are other useful functions there, such as isalpha
, isspace
, etc.
And of course, to give an error message, you will need to use some suitable print function, and to repeat, use some do-while
or while
or similar construct.