cin.get proplem

HELLO THERE
i used this code to assign variable form user input and show what he entered

1
2
3
4
5
int a = cin.get();
		cout << a <<endl;
		int b = cin.get();
		cin.get();
		return 0;


so when user inter number (3) for example the output is 51
i do not know why it is not 3 is user entered
Last edited on
Not sure why you are using cin.get() as this is used to only get one character and treat it as a char, not int (see here: http://www.cplusplus.com/forum/general/465/) That being said, the easiest way to get the correct output would be

1
2
3
int a;
cin >>a;
cout <<a <<endl;
Thank You For Clearing That For Me.
but, still, i don't understand why this:
 
int a = cin.get();

returns number around 48, for example, if you entered 1, the output is 49, if you entered 0, the output will be 48

can anybody explains this?
You may want to use your favourite search engine and search for "ASCII Table", then click on one of the first several links. Then look up the decimal equivalent for the character '1' .
Topic archived. No new replies allowed.