我试图从迭代器中获取索引值。但我不断得到错误“间接需要指针操作数('长'无效)” 任何的想法?我需要得到索引。在以下示例中,它应输出2。
template<typename T>
void practice(T begin, T end) {
T it = begin;
it++;
it++;
auto index = it - begin;
cout << *index;
答案 0 :(得分:1)
cout << index;
无需*
取消引用。