user2172254
user2172254

Reputation:

C++ get Index value in integer from iterator

I am trying to get the index value from iterator. But I keep getting the error "Indirection requires pointer operand ('long' invalid)" Any idea? I need to get the index. on the following example, it should output 2.

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

Upvotes: 2

Views: 169

Answers (1)

John Kugelman
John Kugelman

Reputation: 361556

cout << index;

No need for the * dereference.

Upvotes: 1

Related Questions