d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > C++ Handling Input
Add Reply New Topic New Poll
Member
Posts: 5,988
Joined: May 6 2006
Gold: 30.00
Oct 22 2013 02:03pm
When you have a variable declared

int c;

and you write

cin >> c;

Whats the best way to handle the case where a user inputs a character(s)?

This post was edited by oOn on Oct 22 2013 02:03pm
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Oct 22 2013 03:26pm
Put the user input into a string, then test it to see if it can be converted to integer, just an idea.

This post was edited by Azrad on Oct 22 2013 03:28pm
Member
Posts: 2,757
Joined: Nov 26 2007
Gold: 1,214.81
Oct 23 2013 07:16am
if (cin >> c){
// was an integer
}else{
//wasn't an integer
}
Member
Posts: 1,358
Joined: Dec 30 2012
Gold: 0.10
Oct 23 2013 07:40am
Isdigit()
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll