How to directly assign complex numbers to a variable?

Viewed 9703

Using the complex class and library, how do I assign a complex number to a variable?

I understand that I can set the value when I first instantiate the complex number.
I also understand that I can assign one instantiated complex number to another.
How can I directly assign a complex number to a variable?

Reference:
http://www.cplusplus.com/reference/complex/complex/operators/

Example:

#include <iostream>
#include <complex>

int main() {
    complex<double> a(1.2,3.4), b;
    cout << a; //-> (1.2,3.4)
    b = a;
    cout << b; //-> (1.2,3.4)
    b = (1.2,3.4);
    cout << b; //-> (3.4,0) <-- what the heck is this??
    return 0;
}
4 Answers
Related