How to limit input?


I'm coding an basic text-rpg and i need to limit an input to only one character. I've searched the web, and found some answers (such as setw) but none of those codes worked for me.. So how to set a limit for numbers of characters in a
"char" variable.
Last edited on
A char variable by definition can only hold data for one character, otherwise you're referring to a c_string which is an array for chars.

I don't know what you're trying to do specifically but it sounds like you might want to use
cin.get()

http://www.cplusplus.com/reference/istream/istream/get/


Hope this helps,

Regards,

Hugo
getch and getche are very useful but nonstandard tools that you may enjoy using here.
Topic archived. No new replies allowed.