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

备注

在字符串之间的一个字典比较的字符比较这些字符直到:

  • 它发现两个对应的字符不相等,并且,它们的比较结果执行因为比较在字符串之间。

  • 它不查找不相等,但是,一个字符串比其他具有多个字符,因此,较短的字符串大于较长字符串被视为较少。

  • 它不查找不相等和发现字符串具有字符数相同,因此,字符串相等。

示例

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