Defined in header <complex> | ||||
---|---|---|---|---|
| (1) | (since C++14) | ||
| (2) | (since C++14) | ||
| (3) | (since C++14) |
Forms a std::complex
literal representing an imaginary number.
Parameters
arg | - | the value of the imaginary number |
Return value
The std::complex
literal with the real part zero and imaginary part arg
.
Notes
These operators are declared in the namespace std::literals::complex_literals
, where both literals
and complex_literals
are inline namespaces. Access to these operators can be gained with using namespace std::literals
, using namespace std::complex_literals
, and using namespace std::literals::complex_literals
.
Even though if
is a keyword in C++, it is a ud-suffix of the literal operator of the form operator ""if
and in the literal expressions such as 1if
or 1.0if
because it is not separated by whitespace and is not a standalone token.
Possible implementation
First version | ||
---|---|---|
| ||
Second version | ||
| ||
Third version | ||
|
Example
1 2 3 4 5 6 7 8 9 | #include <iostream> #include <complex> int main() { using namespace std::complex_literals; std::complex< double > c = 1.0 + 1i; std::cout << "abs" << c << " = " << abs (c) << '\n' ; } |
Output:
1 | abs (1,1) = 1.41421 |
See also
constructs a complex number (public member function) | |
operator=
| assigns the contents (public member function) |
C documentation for I |
Please login to continue.