C++入门经典-例2.7-控制cout打印格式程序

1:代码如下:

C++入门经典-例2.7-控制cout打印格式程序C++入门经典-例2.7-控制cout打印格式程序
// 2.7.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
void main()
{
    double a=123.456789012345;
    cout << a << endl;//默认输出格式(精度为6)  
    cout << setprecision(9) << a << endl;//设置浮点数的输出精度为9,取9位有效数字
    cout << setprecision(6);    //恢复默认格式(精度为6)
    cout << setiosflags(ios::fixed); 
    cout << setiosflags(ios::fixed) << setprecision(8) << a << endl;//取小数点后8位有效数字
    cout << setiosflags(ios::scientific) << a << endl;
    cout << setiosflags(ios::scientific) << setprecision(4) << a << endl; 
}
View Code

运行结果:

C++入门经典-例2.7-控制cout打印格式程序

2:程序中有几个语句不太明白。

posted @ 2017-09-11 10:03 一串字符串 阅读(...) 评论(...) 编辑 收藏

相关文章:

  • 2021-06-07
  • 2021-08-29
  • 2022-12-23
  • 2022-02-17
  • 2021-04-07
猜你喜欢
  • 2021-04-27
  • 2021-05-28
  • 2022-12-23
  • 2021-11-22
相关资源
相似解决方案