basic_string::difference_type

提供两个迭代之间的差异引用同一字符串中元素的类型。

typedef typename allocator_type::difference_type difference_type;

备注

带符号整数类型描述可以表示任何两个元素之间地址的区别在于该控件序列的对象。

对于类型 字符串,它与 ptrdiff_t等效。

示例

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

要求

标头: <string>

命名空间: std

请参见

参考

basic_string Class