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

时间:2013-08-10 05:54:42

标签: c++ templates pointers indexing iterator

我试图从迭代器中获取索引值。但我不断得到错误“间接需要指针操作数('长'无效)” 任何的想法?我需要得到索引。在以下示例中,它应输出2。

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

1 个答案:

答案 0 :(得分:1)

cout << index;

无需*取消引用。