다음을 통해 공유


operator==(<string>)

Tests if the string object on the left side of the operator is equal to the string object on the right side.

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
    A C-style string or an object of type basic_string to be compared.

  • _Right
    A C-style string or an object of type basic_string to be compared.

반환 값

true if the string object on the left side of the operator is lexicographically equal to the string object on the right side; otherwise false.

설명

The comparison between string objects is based on a pairwise lexicographical comparison of their characters. Two strings are equal if they have the same number of characters and their respective character values are the same. 그렇지 않으면 두 개체는 서로 다른 개체입니다.

예제

// 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==