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 对象。_Right
用 . 式字符串或类型要比较的 basic_string 对象。
返回值
true,如果运算符左侧的字符串对象与右侧的字符串字典对象是小于;为 false。
备注
在字符串之间存在着字典来比较字符由比较这些字符之前:
找到不相等两个相应的字符,并且,它们的比较结果采用作为比较在字符串之间。
它不以查找不相等,但字符串与其他具有多个字符,因此,较短的字符串大于较长的字符串被视为小。
它不查找不相等和查找字符串有字符数相同,并且,因此字符串相等。
示例
// 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