16.迭代器距离

Posted foremember

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}

 

以上是关于16.迭代器距离的主要内容,如果未能解决你的问题,请参考以下文章

Python基础-16生成器-迭代器

Python基础-16生成器-迭代器

size_type 中迭代器之间的长度

在片段着色器中丢失纹理定义

16迭代器模式

JAVA SCRIPT设计模式--行为型--设计模式之Iterator迭代器模式(16)