次の方法で共有


operator<= (in <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_le.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 or equal to "
           << "the string s2." << endl;
   else
      cout << "The string s1 is greater than "
           << "the string s2." << 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 string s1 is less than or equal to "
           << "the string s3." << endl;
   else
      cout << "The string s1 is greater than "
           << "the string s3." << endl;

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

必要条件

ヘッダー: の <文字列>

名前空間: std

参照

関連項目

string::operator<=