zoukankan      html  css  js  c++  java
  • 格式化输入输出

    #include<iostream>
    #include<cmath>
    #include<iomanip>
    using namespace std;
    
    int main()
    {
        cout<<"default bool values: "<<true<<" "<<false<<"
    alpha bool value: "<<boolalpha<<true<<" "<<false<<endl;
        cout<<noboolalpha<<endl;
        cout<<"default: "<<20<<" "<<1924<<endl;
        cout<<"octal: "<<oct<<20<<" "<<1024<<endl;
        cout<<"hex: "<<hex<<20<<" "<<1024<<endl;
        cout<<"decimal: "<<dec<<20<<" "<<1024<<endl;
        cout<<endl;
        cout<<showbase;
        cout<<uppercase<<"default: "<<20<<" "<<1924<<endl;
        cout<<uppercase<<"octal: "<<oct<<20<<" "<<1024<<endl;
        cout<<uppercase<<"hex: "<<hex<<20<<" "<<1024<<endl;
        cout<<uppercase<<"decimal: "<<dec<<20<<" "<<1024<<endl;
        cout<<nouppercase<<noshowbase;
        cout<<showbase<<"hex: "<<hex<<20<<" "<<1024<<noshowbase<<endl;
        cout<<dec;
        cout<<endl;
        cout<<"precision: "<<cout.precision()<<",Value: "<<sqrt(2.0)<<endl;
        cout.precision(12);
        cout<<"precision: "<<cout.precision()<<",Value: "<<sqrt(2.0)<<endl;
        cout<<setprecision(3);
        cout<<"precision: "<<cout.precision()<<",Value: "<<sqrt(2.0)<<endl;
        cout<<"default format: "<<100*sqrt(2.0)<<'
    '
            <<"scientific: "<<scientific<<100*sqrt(2.0)<<'
    '
            <<"fixed decimal: "<<fixed<<100*sqrt(2.0)<<'
    ';
           // <<"hexadecimal: "<<std::hexfloat<<100*sqrt(2.0)<<'
    '
            //<<"use defaults: "<<defaultfloat<<100*sqrt(2.0)<<"
    
    "
        cout<<endl;
        int i=-16;
        double d=3.14159;
        cout<<"i: "<<setw(12)<<i<<"next col"<<'
    '
            <<"d: "<<setw(12)<<d<<"next col"<<'
    ';
        cout<<left
            <<"i: "<<setw(12)<<i<<"next col"<<'
    '
            <<"d: "<<setw(12)<<d<<"next col"<<'
    '
            <<right;
        cout<<right
            <<"i: "<<setw(12)<<i<<"next col"<<'
    '
            <<"d: "<<setw(12)<<d<<"next col"<<'
    ';
        cout<<internal
            <<"i: "<<setw(12)<<i<<"next col"<<'
    '
            <<"d: "<<setw(12)<<d<<"next col"<<'
    ';
        cout<<setfill('#')
            <<"i: "<<setw(12)<<i<<"next col"<<'
    '
            <<"d: "<<setw(12)<<d<<"next col"<<'
    '
            <<setfill(' ');
        char ch;
        cin>>noskipws;
        while(cin>>ch)
            cout<<ch;
        cin>>skipws;
    }
  • 相关阅读:
    美团这个项目是用来干啥的?
    基于C#的机器学习--面部和动态检测-图像过滤器
    基于C#的机器学习--颜色混合-自组织映射和弹性神经网络
    EF Core For Oracle11中Find FirstOrDefault等方法执行失败
    使用DataContractJsonSerializer发序列化对象时出现的异常
    数据库空值排序
    C#浅拷贝与深拷贝测试
    C#排序算法的实现---快速排序
    C#排序算法的实现---选择排序
    C#排序算法的实现---冒泡排序
  • 原文地址:https://www.cnblogs.com/wuchanming/p/3953887.html
Copyright © 2011-2022 走看看