这段代码中两种修改方式只有第二种是正确的,这是为什么呢?
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
map<int, int> mp1, mp2;
int num1 = 0, num2 = 0;
signed main()
{
mp1[1] = mp1[2] = 1;
mp2[1] = mp2[2] = 1;
for (auto it : mp1)
it.second = ++num1;
for (auto it : mp2)
mp2[it.first] = ++num2;
for (auto it : mp1)
cout << it.second << ' ';
cout << endl;
for (auto it : mp2)
cout << it.second << ' ';
cout << endl;
return 0;
}