共用方式為


basic_string::difference_type

提供兩個 Iterator 之間的差別參考相同字串內之項目的型別。

typedef typename allocator_type::difference_type difference_type;

備註

帶正負號的整數 (Unsigned Integer) 型別描述可代表任何兩個項目之間的電子郵件地址的差異在受控制序列的物件。

如需型別 字串,它與 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