Partager via


basic_string::difference_type

Un type qui fournit la différence entre deux itérateurs qui font référence à des éléments dans la même chaîne.

typedef typename allocator_type::difference_type difference_type;

Notes

Le type d'entier signé décrit un objet qui peut représenter la différence entre les adresses de deux éléments quelconques de la séquence contrôlée.

Pour le type string, il correspond à ptrdiff_t.

Exemple

// basic_string_diff_type.cpp
// compile with: /EHsc
#include <string>
#include <iostream>

int main( ) 
{
   using namespace std;
   string str1 ( "quintillion" );
   cout << "The original string str1 is: " << str1 << endl;
   basic_string <char>::size_type indexChFi, indexChLi;

   indexChFi = str1.find_first_of ( "i" );
   indexChLi = str1.find_last_of ( "i" );
   basic_string<char>::difference_type diffi = indexChLi - indexChFi;

   cout << "The first character i is at position: "
        << indexChFi << "." << endl;
   cout << "The last character i is at position: "
        << indexChLi << "." << endl;
   cout << "The difference is: " << diffi << "." << endl;
}
  

Configuration requise

En-tête : <chaîne>

Espace de noms : std

Voir aussi

Référence

basic_string, classe