vector::difference_type
提供两个迭代之间的差异引用同一矢量中元素的类型。
typedef typename Allocator::difference_type difference_type;
备注
因为对元素的指针包含其地址,difference_type 也称为元素数。两个指针之间的。
迭代器 通常用于访问向量元素。
示例
// vector_diff_type.cpp
// compile with: /EHsc
#include <iostream>
#include <vector>
#include <algorithm>
int main( )
{
using namespace std;
vector <int> c1;
vector <int>::iterator c1_Iter, c2_Iter;
c1.push_back( 30 );
c1.push_back( 20 );
c1.push_back( 30 );
c1.push_back( 10 );
c1.push_back( 30 );
c1.push_back( 20 );
c1_Iter = c1.begin( );
c2_Iter = c1.end( );
vector <int>::difference_type df_typ1, df_typ2, df_typ3;
df_typ1 = count( c1_Iter, c2_Iter, 10 );
df_typ2 = count( c1_Iter, c2_Iter, 20 );
df_typ3 = count( c1_Iter, c2_Iter, 30 );
cout << "The number '10' is in c1 collection " << df_typ1 << " times.\n";
cout << "The number '20' is in c1 collection " << df_typ2 << " times.\n";
cout << "The number '30' is in c1 collection " << df_typ3 << " times.\n";
}
要求
标头: <vector>
命名空间: std