dictionary - map.end() error "iterator not dereferenceable" c++ -
this question has answer here:
- iterators can't access problems properly 3 answers
//works cout << "map[0] value " << doublestatsmap.begin()->first<< endl; //gives error cout << "map[last value " << doublestatsmap.end()->first << endl;
im trying value of last element of map. works correctly "map.begin->first" giving "map/set iterator not dereferencable" "map.end()->first". cant empty map has beginning has end. i've read says should work. suggestions appreciated!
trying end iterator causes undefined behavior.
to last item, can use std::map::rbegin()
.
// cout << "map[last value " << doublestatsmap.end()->first << endl; cout << "map[last value " << doublestatsmap.rbegin()->first << endl;
wiki
Comments
Post a Comment