###### setiosflags() 的好处多多

#include<iostream>
#include<cmath>
using namespace std;
int main() {

cout << "sqrt(2000) = " << sqrt( 2000 ) << endl;
return 0;
}

#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main() {
cout << setprecision( 1 );
cout << "sqrt(2000) = " << sqrt( 2000 ) << endl;
return 0;
}   //结果为4e+001

int main() {
cout << setprecision( 1 );
cout << "sqrt(2000) = " << sqrt( 2000 ) << endl;
return 0;
}    //结果为45

int main() {
cout << setprecision( 3 );
cout << "sqrt(2000) = " << sqrt( 2000 ) << endl;
return 0;
} //结果为44.7

int main() {
cout << setiosflags( ios::fixed ) << setprecision( 1 );
cout << "sqrt(2000) = " << sqrt( 2000 ) << endl;
return 0;
}  //结果为44.7

int main() {
cout << setiosflags( ios::fixed ) << setprecision( 2 );
cout << "sqrt(2000) = " << sqrt( 2000 ) << endl;
return 0;
}  //结果为44.72

int main() {
cout << setiosflags( ios::fixed ) << setprecision( 3 );
cout << "sqrt(2000) = " << sqrt( 2000 ) << endl;
return 0;
}  //结果为44.721
Apparently, all of the answers are totally correct with any doubt! 结果全部正确，哪怕你来个 setiosflags( ios::fixed ) << setprecision( 1000 ), 结果照样不来半点寒糊！

int main() {
cout << setiosflags( ios::fixed ) << setprecision( 0 );
cout << "sqrt(2000) = " << sqrt( 2000 ) << endl;
return 0;
}  // 结果 45
int main() {
cout << setiosflags( ios::fixed|ios::showpoint ) << setprecision( 0 );
cout << "sqrt(2000) = " << sqrt( 2000 ) << endl;
return 0;
}  //结果 45.

#### C++中setiosflags()的用法

2015-04-05 21:28:16

#### setiosflags的问题

2014-09-16 17:33:06

#### setiosflags(ios::fixed)和setprecision()

2015-11-27 14:37:15

#### C++中setiosflags()函数的用法

2017-09-22 19:56:26

#### setpercision(n) setiosflags(ios::fixed) setiosflags(ios::scientific)

2012-02-16 15:53:57

#### 关于c++浮点数的数字个数setprecision(n)与setiosflags(ios::fixed)

2016-02-22 20:46:43

#### setiosflags

2017-02-26 20:14:12

#### setprecision和setiosflags函数

2012-04-13 16:33:44

#### cout的格式输出

2015-03-31 17:13:19

#### cout<< 精度控制 setprecision、fixed、showpoint的用法总结

2017-03-23 22:45:45

## 不良信息举报

setiosflags() 的好处多多