operator<= (in <string>)

Teste si l'objet String située à gauche de l'opérateur est inférieure ou égale à l'objet String côté droit.

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

Paramètres

  • _Left
    Chaîne de style c ou un objet de type basic_string à comparer.

  • _Right
    Chaîne de style c ou un objet de type basic_string à comparer.

Valeur de retour

true si l'objet String située à gauche de l'opérateur est lexicographique inférieur ou égal à l'objet chaîne du côté droit ; sinon false.

Notes

Une comparaison lexicographique entre les chaînes les compare caractère par caractère jusqu'à ce que :

  • Il recherche deux caractères correspondants inégaux, et le résultat de la comparaison est pris comme résultat d'une comparaison entre les chaînes.

  • Il ne trouve pas d'inégalité, mais une chaîne a plus de caractères que l'autre, et la chaîne plus courte est considérée comme moins que la chaîne plus longue.

  • Il ne trouve pas d'inégalité et recherche que les chaînes ont le même nombre de caractères, les chaînes sont égales.

Exemple

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

Configuration requise

en-tête : <string>

l'espace de noms : DST

Voir aussi

Référence

string::operator<=