共用方式為


char_traits::eq

測試兩個 char_type 字串是否相等。

static bool eq( 
   const char_type& _Ch1,  
   const char_type& _Ch2  
);

參數

  • _Ch1
    為要測試是否相等的第一個字元。

  • _Ch2
    為要測試是否相等的第二個字元。

傳回值

true ,如果第一個字元與第二個字元相等;否則 false

範例

// char_traits_eq.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';

   // Testing for equality
   bool b1 = char_traits<char>::eq ( ch1 , ch2 );
   if ( b1 )
      cout << "The character ch1 is equal "
           << "to the character ch2." << endl;
   else
      cout << "The character ch1 is not equal "
           << "to the character ch2." << endl;

   // An equivalent and alternatively test procedure
   if ( ch1 == ch3 )
      cout << "The character ch1 is equal "
           << "to the character ch3." << endl;
   else
      cout << "The character ch1 is not equal "
           << "to the character ch3." << endl;
}
  

需求

標頭:<string>

命名空間: std

請參閱

參考

char_traits 結構