# 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.

10077 0

2511 0
windows server 2008阿里云ECS服务器安全设置

9159 0

13884 0

4503 0

7365 0

22400 0
+关注
1635

0

《2021云上架构与运维峰会演讲合集》

《零基础CSS入门教程》

《零基础HTML入门教程》