16.迭代器距离

#include<iostream>
#include <string>
#include <vector>
#include <typeinfo>
using std::string;
using std::cout;
using std::cin;
using std::endl;
using std::vector;

int main() {
    vector<int> v;
    for (decltype(v.size()) i = 2; i < 10; ++i)
    {
        v.push_back(i);
    }
    auto t = v.end() - v.begin(); 
    // t是ptrdiff_t类型
    // ptrdiff_t是C/C++标准库中定义的一个与机器相关的数据类型。
    // ptrdiff_t类型变量通常用来保存两个指针减法操作的结果。
    cout << t << endl;
    system("pause");
    return 0;
}

 

posted @ 2019-03-12 11:33  虚设经年  阅读(114)  评论(0)    收藏  举报