什么是setprecision(12)和setprecision(012)之间的区别的原因,例如,在c ++? [英] what is the reason for the difference between setprecision (12) and setprecision (012) for example,in c++?

查看:165
本文介绍了什么是setprecision(12)和setprecision(012)之间的区别的原因,例如,在c ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在c ++中,当你写setprecision(12)例如,12是在10的底部,但当你写它像setprecision(012)它是一个八进制数,为什么?


一个八进制整数文字(基数八)
以数字0开头,由一系列八进制数字的
组成。


C ++草稿标准( n1905 )§2.13.1



它与setprecision没有任何关系。


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?

解决方案

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.

这篇关于什么是setprecision(12)和setprecision(012)之间的区别的原因,例如,在c ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆