char_traits::eq_int_type
測試是否表示為 int_type的兩個字元都是相等的。
static bool eq_int_type(
const int_type& _Ch1,
const int_type& _Ch2
);
參數
_Ch1
為要測試是否相等的第一個字元做為 int_type的。_Ch2
為要測試是否相等的第二個字元做為 int_type。
傳回值
true ,如果第一個字元與第二個字元相等;否則 false。
範例
// char_traits_eq_int_type.cpp
// compile with: /EHsc
#include <string>
#include <iostream>
int main( )
{
using namespace std;
char_traits<char>::char_type ch1 = 'x';
char_traits<char>::char_type ch2 = 'y';
char_traits<char>::char_type ch3 = 'x';
// Converting from char_type to int_type
char_traits<char>::int_type int1, int2 , int3;
int1 =char_traits<char>:: to_int_type ( ch1 );
int2 =char_traits<char>:: to_int_type ( ch2 );
int3 =char_traits<char>:: to_int_type ( ch3 );
cout << "The char_types and corresponding int_types are:"
<< "\n ch1 = " << ch1 << " corresponding to int1 = "
<< int1 << "."
<< "\n ch2 = " << ch2 << " corresponding to int1 = "
<< int2 << "."
<< "\n ch3 = " << ch3 << " corresponding to int1 = "
<< int3 << "." << endl << endl;
// Testing for equality of int_type representations
bool b1 = char_traits<char>::eq_int_type ( int1 , int2 );
if ( b1 )
cout << "The int_type representation of character ch1\n "
<< "is equal to the int_type representation of ch2."
<< endl;
else
cout << "The int_type representation of character ch1\n is "
<< "not equal to the int_type representation of ch2."
<< endl;
// An equivalent and alternatively test procedure
if ( int1 == int3 )
cout << "The int_type representation of character ch1\n "
<< "is equal to the int_type representation of ch3."
<< endl;
else
cout << "The int_type representation of character ch1\n is "
<< "not equal to the int_type representation of ch3."
<< endl;
}
需求
標頭:<string>
命名空間: std