Inputting 0101 and store as 101

Is there any way to do that? For example, the user input 0101 to the program and the program stores the value as 101 in integer type.

I tried this:

int val = 0101;
cout<<val<<endl;

the output is: 65

um... when I did the same in my calculator, this phenomenon did not happen.

Please advise.
cout<< means output.. and you need input. cin >> val by default should give you the result you need. Now you got 65 because in c++ when you start integer with 0 that means base 8 (and 0x means base 16)
When you cin >> somenumber then leading zeros are discounted.

However, in C++ code, leading zeros indicate an octal constant. Hence:
1
2
3
int a = 0101;
int b =  101;
cout << a << " == " << b << ": " << boolalpha << (a == b) << endl;


The constant '101' is equal to decimal 101.
The constant '0101' is equal to decimal 65.

Hope this helps.
Topic archived. No new replies allowed.