C complex number usage
Michael ODonnell
michael.odonnell at comcast.net
Sun Jan 6 18:06:08 EST 2008
JerryF wrote:
>There is a bug in your code:
>c = (a,b); // form the complex number
>This is not initialzing c. It is assigning a to c.
Oh. Duh. He's right.
Some variations:
#include <cstdlib>
#include <iostream>
#include <complex>
using namespace std;
int main(int argc, char *argv[])
{
double a, b;
a = 1.1; // a is the real part
b = 2.2; // b is the imaginary part
complex<double> c(a, b);
// c = (a,b); // form the complex number
cout << "C: " << c << "\n";
complex<double> d;
d.real() = 11.11;
d.imag() = 12.12;
cout << "D: " << d << "\n";
complex<double> *e;
e = new complex<double> (21.21, 22.22);
cout << "E: " << *e << "\n";
return EXIT_SUCCESS;
}
More information about the gnhlug-discuss
mailing list