Oto mój kod:Decrement od końca std :: map
#include <iostream>
#include <map>
using namespace std;
int main() {
map<int , int > myMap;
map<int , int>::iterator it;
myMap.insert(pair<int , int>(1,2));
myMap.insert(pair<int , int>(671,223));
myMap.insert(pair<int , int>(353,245352));
it = myMap.end() - 1;
cout << it->first << it->second << endl;
return 0;
}
Kompilacja ten kod generuje następujący błąd kompilacji:
error: no match for ‘operator-’ (operand types are ‘std::map<int, int>::iterator {aka std::_Rb_tree_iterator<std::pair<const int, int> >}’ and ‘int’)
it = myMap.end() - 1;
nie wiem dlaczego ja dostaję ten błąd ponieważ myślę, że operacje arytmetyczne są dozwolone we wszystkich typach iteratorów.
error: 'prev' nie jest członkiem 'std', otrzymuję ten błąd. Czy potrzebuję do tego jakiegoś pliku nagłówkowego? –
@BhawandeepSingla - '' –
StoryTeller
Zawarłem to, wciąż otrzymuję ten sam błąd. Jakieś inne rzeczy, które muszę dodać? –