operator<< (<complex>)

插入指定的一个复数到输出流。

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

参数

  • _Ostr
    该复数形式输入的输出流。

  • _Right
    要编码的复数输出流

返回值

写入指定的复数的值设置为 _Ostr 的以分析格式:( 实部,虚拟部分 )。

备注

重载输出流,以便将接受一个复数形式的,因此,其默认输出格式是分析格式。

示例

// 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>

命名空间: std