c++出力制御


1出力精度制御
#include<iostream>
#include <iomanip>//          
using namespace std;

int main(){

    
    streamsize prec=cout.precision(); //             
    cout<<"default precision size is "<<prec<<endl;
    
    cout<<setprecision(3);//     
    double x;
    while(cin>>x){
        cout<<"the current input x is "<<x<<endl;              
    }
    
    cout<<setprecision(prec);//       
    double temp=1.3333333;
    cout<<"the value is "<<temp<<endl;
    
    cout<<"end input!!!!!!!!!!!"<<endl;

    system("pause");
    return 0;
}

出力:
default precision size is 6
1.2345
the current input x is 1.23
123456
the current input x is 1.23e+005
quit
the value is 1.33333
end input!!!!!!!!!!!