C++ "int"

Associate
Joined
21 Feb 2004
Posts
886
Hello,

I have an int which is 00, however when i print it out on the screen it only produces one zero when i want both or even if i have 02 it only prints 2. Is there a function or a character that allows me to include both zeros?

Thank you,

Eliot.
 
Soldato
Joined
31 May 2006
Posts
4,239
Location
127.0.0.1
As I understand it an interger can only be a whole number and as such 00 or 02 are not whole numbers. You would need to convert it to a string. cstr is the command in VB. Sorry don't know what c++ is.
 
Soldato
Joined
12 Apr 2004
Posts
11,788
Location
Somewhere
The int datatype stores a number only, with no formatting information associated with it. When you stored 01 in the variable it just stores it as the number 1 because that's what it is. This makes sense because when you have a number, the only thing you're interested in usually is what that number is, not how to display it. Formatting it for display is sensitive to the context in which you're displaying it.

Also, for future reference, putting a zero in front of a number in C++ turns it into an octal literal, that is an integer specified in base 8 rather than base 10. For example, foo = 010; would result in the number 8 (written as 10 in base 8) being stored in foo. You can also start a literal with 0x to have C++ interpret it as a hex number.
 
Back
Top Bottom