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
C. 式字串或型別要比較的 basic_string 物件。_Right
C. 式字串或型別要比較的 basic_string 物件。
傳回值
true ,如果在運算子左方的字串物件動詞命令一般地大於右邊的字串物件;否則 false。
備註
在字串之間的比較字元所比較字元直到:
找到兩個對應的字元視為不相同,因此,其比較的結果會因為比較的字串。
它不會尋找不等比較,不過,一串比其他有多個字元,因此,較短的字串會視為小於較長的字串。
它不會出現在發現字串的字元數,和,因此字串相等。
範例
// string_op_gt.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 = "stricture";
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 greater than "
<< "the string s2." << endl;
else
cout << "The string s1 is not 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 ( s3 > s1 )
cout << "The string s3 is greater than "
<< "the string s1." << endl;
else
cout << "The string s3 is not greater than "
<< "the string s1." << 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 greater than "
<< "the string s3." << endl;
else
cout << "The string s2 is not greater than "
<< "the string s3." << endl;
}
需求
標頭:<string>
命名空間: std