Share via


basic_string::difference_type

Un tipo que proporciona la diferencia entre dos iteradores que hacen referencia a elementos dentro de la misma cadena.

typedef typename allocator_type::difference_type difference_type;

Comentarios

El tipo con signo integer describe un objeto que puede representar la diferencia entre las direcciones de los dos elementos de la secuencia controlada.

para cadenaescrito, es equivalente a ptrdiff_t.

Ejemplo

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

Requisitos

encabezado: <cadena>

espacio de nombres: std

Vea también

Referencia

basic_string Class