This topic has not yet been rated - Rate this topic

complex::real

Gets or sets the real component of a complex number.

Type real( ) const;
Type real(const Type& _Right);
_Right

A complex number whose real value is to be extracted.

The real part of the complex number.

For a complex number a + bi, the real part or component is Re(a + bi) = a.

// complex_class_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 = c1.real ( );
   cout << "The real part of c1 is c1.real ( ) = "
        << dr1 << "." << endl;

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

Header: <complex>

Namespace: std

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.