格式输出的问题

来源:互联网 发布:尔雅网络app叫什么 编辑:程序博客网 时间:2024/05/21 19:27
//格式输出的问题
#include <iostream>
using namespace std ;
void main()
double x = 22.0/7 ;
int i ;
for( i=1; i<=5; i++ )
    { 
cout.precision( i ) ;  
cout << x << endl ; 
//这里输出是按精度输出的,说明原来没设置定点输出
}
cout << "output in scientific :/n" ;
#if 0 
cout.setf(ios::scientific, ios::fixed ) ;// 清除原有设置,科学示数法输出
//清除了设置输出的结果是按设置精度的结果
#else 
cout.setf(ios::scientific) ;
//没有清楚原有设置,因为原本就没设置,但是输出的结果竟然比设置的精度多了一位
#endif ;
for( i=1; i<=5; i++ )
    { 
cout.precision(i) ;   
cout << x*1e5 << endl ; 
}
}
//这就让人纳闷了,为啥清除了原本根本就没的设置后输出的结果就不同了呢??
原创粉丝点击