In c++ when you write setprecision (12) for example, 12 is in the base of 10 but when you write it like setprecision (012) it is an octal number,why?
views:
96answers:
3
+12
A:
Because constants with leading zeros (other than leading 0x) are always octal:
An octal integer literal (base eight) begins with the digit 0 and consists of a sequence of octal digits.
C++ draft standard (n1905) §2.13.1
It has nothing at all to do with setprecision.
Matthew Flaschen
2010-04-29 20:56:09
thanks for the sufficient explanation.
Ehsan Mamakani
2010-04-29 21:07:12
@Ehsan: click the checkmark next to the answer to officially say that.
Potatoswatter
2010-04-29 21:09:13
already did it man!
Ehsan Mamakani
2010-04-29 21:25:30
+3
A:
In C++, if an integer literal begins with a 0
digit (and that 0
is not followed by a x
), the following digits are treated as octal digits.
strager
2010-04-29 20:56:31
+4
A:
Because that's how it worked in C. Back when C was designed, octal numbers were in frequent use, so they put in a notation for them. Currently, it's rarely helpful and mostly confusing.
David Thornley
2010-04-29 20:57:07