operator> (<string>)

Test se l'oggetto stringa a sinistra dell'operatore è maggiore dell'oggetto stringa dalla destra.

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
   );

Parametri

  • _Left
    Stringa di tipo c o un oggetto di tipo basic_string da confrontare.

  • _Right
    Stringa di tipo c o un oggetto di tipo basic_string da confrontare.

Valore restituito

true se l'oggetto stringa a sinistra dell'operatore è lessicografico maggiore dell'oggetto stringa da destra; in caso contrario false.

Note

Lessicografico un confronto tra stringhe vengono confrontate carattere per carattere fino a:

  • Cerca due caratteri corrispondenti diversi e il risultato del confronto viene utilizzato come risultato del confronto tra stringhe.

  • Non trova disuguaglianze, ma una stringa ha più caratteri dell'altra e la stringa più breve è considerata minore della stringa più lunga.

  • Non trova disuguaglianze e rileva che le stringhe hanno lo stesso numero di caratteri e pertanto le stringhe sono uguali.

Esempio

// 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;
}
  
  
  
  
  
  

Requisiti

intestazione: <string>

Spazio dei nomi: deviazione standard

Vedere anche

Riferimenti

string::operator>