An iterator needs to be dereferenced *it or it->first so its internal data can be accessed.
If you have an std::unordered_map<Key, Value> (or std::map<Key, Value>), its iterator points to a key-value pair, represented as std::pair<const Key, Value>.
1
2
3
autoit=my_map.find("some_key");std::cout<<(*it).first<<" : "<<(*it).second<<std::endl;// see "some key", and valuestd::cout<<it->first<<" : "<<it->second<<std::endl;
std::set, std::unordered_set: Iterator points directly to the value (the key itself).
1
2
3
4
5
6
std::unordered_set<int>s;autoit=s.begin();intvalue=*it;intvalue2=it.operator*();intvalue3=*it;// same thingintvalue4=it->second;// ❌ doesn't work! No .second — it's just a value
std::vector<T> / std::deque<T> / std::list<T>:
1
2
3
std::vector<int>v;autoit=v.begin();*it
std::vector<std::pair<» or similar
1
2
3
4
std::vector<std::pair<int,std::string>>vp;autoit=vp.begin();it->first// valid!it->second// also valid!
std::tuple in containers
1
2
3
4
std::vector<std::tuple<int,std::string>>vt;autoit=vt.begin();std::get<0>(*it);// get the first itemstd::get<1>(*it);// get the second item