zoukankan      html  css  js  c++  java
  • C++入门经典-例2.7-控制cout打印格式程序

    1:代码如下:

    // 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

    运行结果:

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

  • 相关阅读:
    lnmp 优化
    linux-lnmp 搭建报错
    nfs 配置
    全网备份脚本rsync
    .Net面试题二
    软件设计模式
    .Net面试题一
    asp.net运行机制
    NHiberante的优缺点
    什么是架构、框架、模式和平台
  • 原文地址:https://www.cnblogs.com/lovemi93/p/7503588.html
Copyright © 2011-2022 走看看