C++输出流基本操作

代码如下:

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

const double PI = 3.1415926535;
const double SPEED_OF_LIGHT = 2.99792458E+8;
const double FINE_STRUTYRE = 7.2573525E-3;

void print_Table();

int main(int argc, char const *argv[])
{
    cout << uppercase << right;
    cout << "Default format:" << endl << endl;
    print_Table();
    cout << endl << "Fixed format:" << fixed << endl << endl;
    print_Table();
    cout << endl << "Secientific format:" << scientific << endl << endl;
    print_Table();
    return 0;
}


void print_Table()
{
    cout << "prec    |        pi         |    speed of light |    fine structure" << endl;
    cout << "--------+---------------+------------------+------------------" << endl;
    for(int i = 0;i <=6;++i)
    {
        cout << setw(7) << i << " |";
        cout << " " << setw(13) << setprecision(i) << PI << " |";
        cout << " " << setw(16) << setprecision(i) << SPEED_OF_LIGHT << " |";
        cout << " " << setw(14) << setprecision(i) << FINE_STRUTYRE << endl;
    }

}

运行结果:
运行结果

手机上阅读

本文由 giao创作, 采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
原文地址:《C++输出流基本操作》

 最后一次更新于2018-12-20

3 条评论

  1. ohmyga

    仰望大佬.jpg

    By ohmyga at October 24th, 2018 at 12:52 pm.  

  2. 纱娜子Hq

    2333

    By 纱娜子Hq at October 22nd, 2018 at 09:01 pm.  

  3. 今天不聊天

    晓月斋木有小鸡鸡

    By 今天不聊天 at October 22nd, 2018 at 02:26 pm.  

添加新评论

Markdown is supported.