次の方法で共有


operator== (<string>)

演算子の左側の文字列オブジェクトが右側の文字列オブジェクトと等しいかどうかを調べます。

template<class CharType, class Traits, class Allocator>
   bool operator==(
      const basic_string<CharType, Traits, Allocator>& _Left,
      const basic_string<CharType, Traits, Allocator>& _Right
   );
template<class CharType, class Traits, class Allocator>
   bool operator==(
      const basic_string<CharType, Traits, Allocator>& _Left,
      const CharType *_Right
   );
template<class CharType, class Traits, class Allocator>
   bool operator==(
      const CharType *_Left,
      const basic_string<CharType, Traits, Allocator>& _Right
   );

パラメーター

  • _Left
    basic_string における. の式の文字列を比較するオブジェクト。

  • _Right
    basic_string における. の式の文字列を比較するオブジェクト。

戻り値

演算子の左側の文字列オブジェクトが右側の文字列オブジェクトと辞書式に等しいtrue ; それ false

解説

文字列オブジェクトの比較は、文字のペアに辞書式の比較に基づいています。2 文字列は、文字の数が同じであり、それぞれの文字の値が同じ場合は等しくなります。それ以外の場合は等しくありません。

使用例

// string_op_eq.cpp
// compile with: /EHsc
#include <string>
#include <iostream>

int main( ) 
{
   using namespace std;

   // Declaring an objects of type basic_string<char>
   string s1 ( "pluck" );
   string s2 ( "strum" );
   cout << "The basic_string s1 = " << s1 << "." << endl;
   cout << "The basic_string s2 = " << s2 << "." << endl;

   // Declaring a C-style string
   char *s3 = "pluck";
   cout << "The C-style string s3 = " << s3 << "." << endl;

   // First member function: comparison between left-side object
   // of type basic_string & right-side object of type basic_string
   if ( s1 == s2 )
      cout << "The strings s1 & s2 are equal." << endl;
   else
      cout << "The strings s1 & s2 are not equal." << endl;

   // Second member function: comparison between left-side object
   // of type basic_string & right-side object of C-syle string type
   if ( s1 == s3 )
      cout << "The strings s1 & s3 are equal." << endl;
   else
      cout << "The strings s1 & s3 are not equal." << endl;

   // Third member function: comparison between left-side object
   // of C-syle string type & right-side object of type basic_string
   if ( s3 == s2 )
      cout << "The strings s3 & s2 are equal." << endl;
   else
      cout << "The strings s3 & s2 are not equal." << endl;
}
  
  
  
  
  
  

必要条件

ヘッダー: <string>

名前空間: std

参照

関連項目

string::operator==