各位大神们,请问C++中complex.h怎么用?
编程序需要用到复数运算,除了四则运算还包括自然对数运算等,请教一下complex头文件中怎么实现这些运算?非常感谢!!!
#include <iostream> #include <complex> using namespace std; int main(int argc, char *argv[]) { complex<double> a(1, 2), b(3, 4); cout << "a = " << a << ", b = " << b << endl; cout << "a + b = " << a + b << endl; cout << "a * b = " << a * b << endl; cout << "\nthe real part of a is " << real(a) << endl; cout << "the imaginary part of b is " << imag(b) << endl; cout << "the magnitude of a is " << abs(a) << endl; cout << "\ne^a = " << exp(a) << endl; cout << "ln(b) = " << log(b) << endl; return 0; }输出: