How to limit input?

Jun 25, 2018 at 4:13pm

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 Jun 25, 2018 at 4:14pm
Jun 25, 2018 at 9:26pm
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
Jun 26, 2018 at 2:16am
getch and getche are very useful but nonstandard tools that you may enjoy using here.
Topic archived. No new replies allowed.