public member function
<complex>

std::complex::imag

T imag() const;
get (1)
T imag() const;
set (2)
void imag (T val);
Imaginary part
Returns the imaginary part of the complex number.
Returns the imaginary part of the complex number (1), or sets val as the new value for the imaginary part (2).

The imaginary part is the factor by which the imaginary unit (i) is multiplied.

A non-member function exists with the same name: imag.

Parameters

none

Return value

The imaginary part.
T is complex's template parameter.

Example

1
2
3
4
5
6
7
8
9
10
11
12
// complex::imag example
#include <iostream>     // std::cout
#include <complex>      // std::complex

int main ()
{
  std::complex<double> mycomplex (20.0,2.0);

  std::cout << "Imaginary part: " << mycomplex.imag() << '\n';

  return 0;
}

Output:

Imaginary part: 2


See also