How to define Complex variables in C++ and Use of Header file
-
Tuesday, December 20, 2011 4:54 PMCould someone help me on complex variables: complex(a,b), in C++, as to what to use in the header files in Visual Studio 2008, and input and output these complex # to a file?
All Replies
-
Tuesday, December 20, 2011 7:55 PM
Could someone help me on complex variables: complex(a,b), in C++, as to what to use in the header files in Visual Studio 2008, and input and output these complex # to a file?
To use std::complex template in C++ you have to #include <complex> header file.
Then you can use complex<double> or complex<float> basing on the precision you require:
#include <complex>
using std::complex;
complex<double> z1(10.0); // 10 + 0i)
complex<double> z2(-3.0, 4.0) // -3 + 4i
...
To input/output complex numbers to a file, you may want to just input/output their real and coefficient of imaginary part separately.
Giovanni
- Proposed As Answer by Carl DanielModerator Tuesday, December 20, 2011 8:48 PM
- Marked As Answer by Helen ZhaoModerator Wednesday, December 28, 2011 2:07 AM
-
Wednesday, December 28, 2011 2:07 AMModeratorHi Good_Fellow,
I'd like to mark Giovanni's reply as answer. If you have any questions, you can post back and unmark it. We'll continue working with you on this issue.
Thanks for your understanding.
Have a nice day!
Helen Zhao [MSFT]
MSDN Community Support | Feedback to us

