C++从迭代器中获取整数形式的索引值

C++ get Index value in integer from iterator

本文关键字:索引值 整数 获取 迭代器 C++      更新时间:2023-10-16

我正在尝试从迭代器中获取索引值。但我一直得到错误"Indirection需要指针操作数('long'无效)"知道吗?我需要得到索引。在下面的示例中,它应该输出2。

template<typename T>
void practice(T begin, T end) {
    T it = begin;
    it++;
    it++;
    auto index = it - begin;
    cout << *index;
cout << index;

无需*取消引用。