码迷,mamicode.com
首页 > 其他好文 > 详细

格式化输入输出

时间:2014-09-03 16:28:26      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   ar   for   div   sp   

#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int main()
{
    cout<<"default bool values: "<<true<<" "<<false<<"\nalpha 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)<<\n
        <<"scientific: "<<scientific<<100*sqrt(2.0)<<\n
        <<"fixed decimal: "<<fixed<<100*sqrt(2.0)<<\n;
       // <<"hexadecimal: "<<std::hexfloat<<100*sqrt(2.0)<<‘\n‘
        //<<"use defaults: "<<defaultfloat<<100*sqrt(2.0)<<"\n\n"
    cout<<endl;
    int i=-16;
    double d=3.14159;
    cout<<"i: "<<setw(12)<<i<<"next col"<<\n
        <<"d: "<<setw(12)<<d<<"next col"<<\n;
    cout<<left
        <<"i: "<<setw(12)<<i<<"next col"<<\n
        <<"d: "<<setw(12)<<d<<"next col"<<\n
        <<right;
    cout<<right
        <<"i: "<<setw(12)<<i<<"next col"<<\n
        <<"d: "<<setw(12)<<d<<"next col"<<\n;
    cout<<internal
        <<"i: "<<setw(12)<<i<<"next col"<<\n
        <<"d: "<<setw(12)<<d<<"next col"<<\n;
    cout<<setfill(#)
        <<"i: "<<setw(12)<<i<<"next col"<<\n
        <<"d: "<<setw(12)<<d<<"next col"<<\n
        <<setfill( );
    char ch;
    cin>>noskipws;
    while(cin>>ch)
        cout<<ch;
    cin>>skipws;
}

 

格式化输入输出

标签:style   blog   color   os   io   ar   for   div   sp   

原文地址:http://www.cnblogs.com/wuchanming/p/3953887.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!