Although I use an iterator like this,
//include header files using namespace std; int main() { map<int,int> intIntMap; map<int,int>::iterator pos; pos = intIntMap.begin(); intIntMap[0] = 1; intIntMap[3] = 5; intIntMap[4] = 9; intIntMap[5] = 5; //้ๅ cout << (*pos).first << endl; while( pos != intIntMap.end() ) { cout << pos->first << " <---> " << pos->second << endl; pos++; } }
The output signal is 4;
But for now, I'm using an iterator like this:
//include header file using namespace std; int main() { map<int,int> intIntMap; map<int,int>::iterator pos; intIntMap[0] = 1; intIntMap[3] = 5; intIntMap[4] = 9; intIntMap[5] = 5; //้ๅpos = intIntMap.begin(); cout << (*pos).first << endl; while( pos != intIntMap.end() ) { cout << pos->first << " <---> " << pos->second << endl; pos++; } }
The result is what I want;
I want to know what is the difference between using an iterator, what happened to the first iterator when inserting a new key-value pair? Thanks!
addtion: the compiler uses gcc 4.1.2, feeling more confused, for example:

source share