다음을 통해 공유


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
    C 스타일 문자열 형식의 개체 또는 basic_string 비교 해야 합니다.

  • _Right
    C 스타일 문자열 형식의 개체 또는 basic_string 비교 해야 합니다.

반환 값

true 이면 는 문자열 연산자의 왼쪽에서 오른쪽; string 개체 사전순 보다 개체인 경우 그렇지 않으면 거짓.

설명

문자열을 사전순으로 비교 하 여 문자까지 비교합니다.

  • 해당 문자를 두 부등을 발견 하 고 문자열 비교의 결과 비교 결과를 그대로.

  • 없음 부등호를 찾습니다. 문자열의 기타 및 짧은 문자열 간주 하는 것 보다 많은 문자 보다 긴 문자열

  • 부등호 및 검색 문자열의 문자 수가 같아야 하 고 따라서 문자열이 같은지 없음을 찾습니다.

예제

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

int main( )
{
   using namespace std;
   // Declaring an objects of type basic_string<char>
   string s1 ( "strict" );
   string s2 ( "strum" );
   cout << "The basic_string s1 = " << s1 << "." << endl;
   cout << "The basic_string s2 = " << s2 << "." << endl;

   // Declaring a C-style string
   char *s3 = "strict";
   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 string s1 is less than the string s2." << endl;
   else
      cout << "The string s1 is not less than the string s2." << endl;

   // Second member function: comparison between left-hand object
   // of type basic_string & right-hand object of C-syle string type
   if ( s1 < s3 )
      cout << "The string s1 is less than the string s3." << endl;
   else
      cout << "The string s1 is not less than the string s3." << endl;

   // Third member function: comparison between left-hand object
   // of C-syle string type & right-hand object of type basic_string
   if ( s3 < s2 )
      cout << "The string s3 is less than the string s2." << endl;
   else
      cout << "The string s3 is not less than the string s2." << endl;
}
  
  
  
  
  
  

요구 사항

헤더: <string>

네임 스페이스: std

참고 항목

참조

string::operator<