cout.setf(ios::showpoint)和setprecision()
发布日期:2022-04-07 05:21:23 浏览次数:29 分类:技术文章

本文共 588 字,大约阅读时间需要 1 分钟。

#include <iomanip>为头文件。

cout.setf(ios::showpoint) 在c++中是为了保留原有的类型精度(四舍五入原则)。

比如,

#include
#include
using namespace std;int main(){ double a=3; //cout.setf(ios::showpoint); cout<

当我们加上 cout.setf(ios::showpoint)后,结果会保留原来的精度。

比如,

#include
#include
using namespace std;int main(){ double a=3; cout.setf(ios::showpoint); cout<

 如果想在最大精度范围内自定义精度,可以用setprecision();它存在于#include <iomanip>头文件中,必须要。用法举例如下,

#include
#include
#include
using namespace std;int main(){ double a=3; cout.setf(ios::showpoint); cout<
<

转载地址:https://blog.csdn.net/weixin_62659979/article/details/123586495 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Creo4.0 Protoolkit 自带案例编译
下一篇:Could not find a version that satisfies the requirement django- “bootstarp4““

发表评论

最新留言

不错!
[***.144.177.141]2024年03月27日 06时32分48秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章