次の方法で共有


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 の C.の式の文字列と比較するオブジェクト。

  • _Right
    basic_string の C.の式の文字列と比較するオブジェクト。

戻り値

演算子の左側の文字列オブジェクトが辞書式には右側の文字列よりも小さいtrue ;オブジェクト それ false

解説

文字列間の辞書式の比較は文字でそれらを文字までの比較します:

  • 厳密な名前は、対応する 2 文字だけでも等しくない検索、比較結果は文字列間の比較結果しまいます。

  • これは非等値が返されますが、1 文字列に他よりも多くの文字を含み、短い文字列に長い文字列未満と見なされます。

  • これは非等値を検索し、文字列の数が同じで、関数は、文字列が等しいことをお勧めします。

使用例

// 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;
}
  

必要条件

ヘッダー: の <文字列>

名前空間: std

参照

関連項目

string::operator<