Export (0) Print
Expand All

operator<< (<complex>)

Inserts a complex number specified into the output stream.

template<class Type, class Elem, class Traits> 
   basic_ostream<Elem, Traits>& 
      operator<< ( 
         basic_ostream<Elem, Traits>& _Ostr, 
         const complex<Type>& _Right 
      );

_Ostr

The output stream into which the complex number is being entered.

_Right

The complex number to be entered into the output stream

Writes the value of the specified complex number to the _Ostr in a Cartesian format: ( real part, imaginary part ).

The output stream is overloaded so that it will accept any form of a complex number, and its default output format is the Cartesian format.

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

int main( )
{
   using namespace std;
   double pi = 3.14159265359;

   complex <double> c1 ( 3.0 , 4.0 );
   cout << "Complex number c1 = " << c1 << endl;

   complex <double> c2  ( polar ( 2.0 , pi / 6 ) );
   cout << "Complex number c2 = " << c2 << endl;

   // To display in polar form
   double absc2 = abs ( c2 );
   double argc2 = arg ( c2 );
   cout << "The modulus of c2 is: " << absc2 << endl;
   cout << "The argument of c2 is: "<< argc2 << " radians, which is " 
        << argc2 * 180 / pi << " degrees." << endl << endl;
}
Complex number c1 = (3,4)
Complex number c2 = (1.73205,1)
The modulus of c2 is: 2
The argument of c2 is: 0.523599 radians, which is 30 degrees.

Header: <complex>

Namespace: std

Show:
© 2014 Microsoft