用迭代器指针改变map容器的值

map容器的键无法改变,但值可以通过下标和迭代器指针来改变,用迭代器指针改变值的程序如下:

#include "stdafx.h"
#include<iostream>
#include<string>
#include<map>

using namespace std;

int main()
{
	map<string, int> mp;
	map<string, int>::iterator it;
	string str;

	cin >> str;
	mp[str] = 0;
	it = mp.begin();
	it->second = 10;
	cout << mp[str];

	system("pause");
	return 0;
}

程序运行结果如下:



猜你喜欢

转载自blog.csdn.net/Buer_zhu/article/details/80963250