共用方式為


imag

擷取複數的虛數部分。

template<class T> 
   T imag( 
      constexpr complex<T>& ComplexNum 
   );

參數

  • ComplexNum
    要擷取其實數部分的複數。

傳回值

複數的虛數部分作為全域函式。

備註

此樣板函式無法用來修改複數的實數部分。 若要變更實數部分,必須將元件值指派給一個新的複數。

範例

// complexc_imag.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;
}
                 

需求

標頭: <complex>

命名空間: std