【发布时间】:2010-12-19 14:04:30
【问题描述】:
vector<int> nums;
nums.push_back(0);
nums.push_back(1);
nums.push_back(2);
nums.push_back(3);
vector<int>::iterator it = nums.begin();
it++;
cout << "it points to " << *(it) << endl;
for(vector<int>::iterator jt = nums.begin(); jt != nums.end(); jt++) {
cout << (*jt) << endl;
}
cout << endl;
nums.insert(it, 100500);
cout << ">> insert(it, 100500)" << endl << endl;
cout << "it points to " << *(it) << endl;
for(vector<int>::iterator jt = nums.begin(); jt != nums.end(); jt++) {
cout << (*jt) << endl;
}
cout << endl;
it++;
cout << ">> it++" << endl << endl;
cout << "it points to " << *(it) << endl;
for(vector<int>::iterator jt = nums.begin(); jt != nums.end(); jt++) {
cout << (*jt) << endl;
}
cout << endl;
nums.insert(it, 100800);
cout << ">> insert(it, 100800)" << endl << endl;
cout << "it points to " << *(it) << endl;
for(vector<int>::iterator jt = nums.begin(); jt != nums.end(); jt++) {
cout << (*jt) << endl;
}
cout << endl;
it++;
cout << ">> it++" << endl << endl;
cout << "it points to " << *(it) << endl;
for(vector<int>::iterator jt = nums.begin(); jt != nums.end(); jt++) {
cout << (*jt) << endl;
}
cout << endl;
返回
it points to 1
0
1
2
3
>> insert(it, 100500)
it points to 1
0
100500
1
2
3
>> it++
it points to 2
0
100500
1
2
3
>> insert(it, 100800)
it points to 100800
134352185
0
100500
1
2
3
>> it++
it points to 2
134352185
0
100500
1
2
3
我什么都听不懂。帮忙!
mingw g++ 4.5.0 win32
【问题讨论】: