Bootstrap

c++各种常用库

cmath:

开根号:

#include<iostream>
#include<cmath>

using namespace std;

int main(){
	double x=8;
	cout<<pow(x,1.0/3)<<endl;
	return 0;
}

输出:
2 

反三角函数:

  • arcsin用asin
  • arccos用acos
  • arctan用atan
#include<iostream>
#include<cmath>

using namespace std;

int main(){
	cout<<asin(1)<<endl;
	cout<<acos(0)<<endl;
	cout<<atan(1)<<endl;
	return 0;
} 

输出:
1.5708
1.5708
0.785398

iomanip:

输出时保留小数:

#include<iostream>
#include<iomanip>

using namespace std;

int main(){
	double x=3.1415926;
	cout<<fixed<<setprecision(3)<<x<<endl;
	return 0;
}

输出:
3.142 
;