次の方法で共有


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

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

戻り値

演算子の左側の文字列オブジェクトが右側の文字列オブジェクトと辞書式に値以下である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;
}
  
  
  
  
  
  

必要条件

ヘッダー: <string>

名前空間: std

参照

関連項目

string::operator<=