I want to use C++ with complex numbers. Therefore I included #include . Now my question is: How do I declare a variable?(so what is the format ca
The constructor of std::complex has two parameters:
For example:
std::complex my_complex(1,1); //1 + 1i
Also, C++11 introduces user defined literals, wich allows us to implement (Or be implemented by the standard library, as in this C++14 accepted proposal) a literal for easy-to-use complex numbers:
constexpr std::complex operator"" i(float d)
{
return std::complex{0.0L,static_cast( d )};
}
You could use this as follows:
auto my_complex = 1i; // 0 + 1i