運算子!== (<complex>)
測試兩個複數間的不相等比較,其中一個或兩個皆可能屬於實數和虛數部分的類型子集。
template<class T>
constexpr bool operator!=(
const complex<T>& Left,
const complex<T>& Right
);
template<class T>
constexpr bool operator!=(
const complex<T>& Left,
const T& Right
);
template<class T>
constexpr bool operator!=(
const T& Left,
const complex<T>& Right
);
參數
Left
用作測試不相等的複數或其參數類型的物件。Right
用作測試不相等的複數或其參數類型的物件。
傳回值
如果清單不相等為 true;如果 list 相等為 false。
備註
唯有在其實數部分相等且虛數部分也相等時,兩個複數才為相等。 反之則為不相等。
已將作業多載以執行比較測試,而無須將資料轉換成特定格式。
範例
// complex_op_NE.cpp
// compile with: /EHsc
#include <complex>
#include <iostream>
int main( )
{
using namespace std;
double pi = 3.14159265359;
// Example of the first member function
// type complex<double> compared with type complex<double>
complex <double> cl1 ( polar (3.0 , pi / 6 ) );
complex <double> cr1a ( polar (3.0 , pi /6 ) );
complex <double> cr1b ( polar (2.0 , pi / 3 ) );
cout << "The left-side complex number is cl1 = " << cl1 << endl;
cout << "The 1st right-side complex number is cr1a = " << cr1a << endl;
cout << "The 2nd right-side complex number is cr1b = " << cr1b << endl;
if ( cl1 != cr1a )
cout << "The complex numbers cl1 & cr1a are not equal." << endl;
else
cout << "The complex numbers cl1 & cr1a are equal." << endl;
if ( cl1 != cr1b )
cout << "The complex numbers cl1 & cr1b are not equal." << endl;
else
cout << "The complex numbers cl1 & cr1b are equal." << endl;
cout << endl;
// Example of the second member function
// type complex<int> compared with type int
complex <int> cl2a ( 3 , 4 );
complex <int> cl2b ( 5 ,0 );
int cr2a =3;
int cr2b =5;
cout << "The 1st left-side complex number is cl2a = " << cl2a << endl;
cout << "The 1st right-side complex number is cr2a = " << cr2a << endl;
if ( cl2a != cr2a )
cout << "The complex numbers cl2a & cr2a are not equal." << endl;
else
cout << "The complex numbers cl2a & cr2a are equal." << endl;
cout << "The 2nd left-side complex number is cl2b = " << cl2b << endl;
cout << "The 2nd right-side complex number is cr2b = " << cr2b << endl;
if ( cl2b != cr2b )
cout << "The complex numbers cl2b & cr2b are not equal." << endl;
else
cout << "The complex numbers cl2b & cr2b are equal." << endl;
cout << endl;
// Example of the third member function
// type double compared with type complex<double>
double cl3a =3;
double cl3b =5;
complex <double> cr3a ( 3 , 4 );
complex <double> cr3b ( 5 ,0 );
cout << "The 1st left-side complex number is cl3a = " << cl3a << endl;
cout << "The 1st right-side complex number is cr3a = " << cr3a << endl;
if ( cl3a != cr3a )
cout << "The complex numbers cl3a & cr3a are not equal." << endl;
else
cout << "The complex numbers cl3a & cr3a are equal." << endl;
cout << "The 2nd left-side complex number is cl3b = " << cl3b << endl;
cout << "The 2nd right-side complex number is cr3b = " << cr3b << endl;
if ( cl3b != cr3b )
cout << "The complex numbers cl3b & cr3b are not equal." << endl;
else
cout << "The complex numbers cl3b & cr3b are equal." << endl;
cout << endl;
}
需求
標頭: <complex>
命名空間: std