What is the reason for the difference between setprecision (12) and setprecision (012), for example, in C ++?

In C ++ when you write setprecision (12) for example 12 is in base 10, but when you write it as setprecision (012) it is an octal number, why?

+2


a source to share


3 answers


Since constants with leading zeros (other than leading 0x) are always octal:

A cyclic integer literal (base eight) starts at 0 and consists of a sequence of octal digits.



C ++ Draft Standard ( n1905 ) §2.13.1

It has nothing to do with setprecision.

+12


a source


Since this worked in C. Back, when C was designed, octal numbers were often used, so they put a notation in them. Currently, he rarely helps and is mostly confusing.



+5


a source


In C ++, if an integer literal starts with a digit 0

(and 0

does not follow for x

), the following digits are treated as octal digits.

+3


a source







All Articles