complex是个类模板,它可以采用float、double和long double 3种原始类型进行定制
complex同时支持如下操作符:
+ - * / = += -= *= /= == !=
函数 | 含义 |
real() | 返回复数的实部 |
imag() | 返回复数的虚部 |
abs(x) | 返回复数x 的模 |
arg(x) | 返回复数x的相角 |
conj(x) | 返回复数x的共轭复数 |
norm(x) | 返回复数x的模的平方 |
#include<bits/stdc++.h>
#include<complex>//在这个头文件里
using namespace std;
typedef complex<double>E;
int main()
{
complex<double>a(1.1,16),b(1,2),c(3,4);
cout<<a<<endl;//输出 (1.1,16)
cout<<b+c<<endl;//输出 (4,6)
cout<<b*c<<endl;//输出 (-5,10)
printf("%.f\n",a.real());// 1 返回
printf("%.3f\n",a.imag()); //16.00;
printf("%.5f\n",abs(b));//2.23607
printf("%.5f\n",arg(c));//
complex<int>s[10];
s[0]=4;//这里只是给实部赋值了 虚部还是0
cout<<s[0]<<endl;//(4,0);
return 0;
}