Export (0) Print
Expand All

real

Extracts the real component of a complex number.

template<class Type> 
   Type real( 
      const complex<Type>& _ComplexNum 
   );

_ComplexNum

The complex number whose real part is to be extracted.

The real part of the complex number as a global function.

This template function cannot be used to modify the real part of the complex number. To change the real part, a new complex number must be assigned the component value.

// complex_real.cpp
// compile with: /EHsc
#include <complex>
#include <iostream>

int main( )
{
   using namespace std;
   complex <double> c1 ( 4.0 , 3.0 );
   cout << "The complex number c1 = " << c1 << endl;

   double dr1 = real ( c1 );
   cout << "The real part of c1 is real ( c1 ) = "
        << dr1 << "." << endl;

   double di1 = imag ( c1 );
   cout << "The imaginary part of c1 is imag ( c1 ) = "
        << di1 << "." << endl;
}
The complex number c1 = (4,3)
The real part of c1 is real ( c1 ) = 4.
The imaginary part of c1 is imag ( c1 ) = 3.

Header: <complex>

Namespace: std

Show:
© 2014 Microsoft