I just can't undestand why swap() function can't work? It also receives two iterators. Can anyone tell me the reason?
#include <iostream> #include <vector> using namespace std; int main() { vector<int> vt; vt.push_back(0); vt.push_back(1); vector<int>::iterator it1 = vt.begin(); vector<int>::iterator it2 = ++vt.begin(); cout << vt[0]; // 0 cout << vt[1] << endl; // 1 swap(it1, it2); cout << vt[0]; // still 0 cout << vt[1] << endl; // still 1 system("pause"); return 0; }
*it1and*it2after theswap.