c++ map迭代器

#include <stdio.h>
#include <map>
using namespace std;

int main(){
        map<int, int> mp;
        for (int i = 0; i < 10; i ++){
                mp[i] = i;
        }

		//count
		if (mp.count(0)) {
			printf("yes
");
		} else {
			printf("no
");
		}

		//find
		map<int, int>::iterator it_find=mp.begin();
		it_find = mp.find(9);
		if(it_find != mp.end()) {
			it_find->second = 20;
		} else {
			printf("nno
");
		}

		//erase
		//mp.erase(it_find);

		mp.insert(map<int, int>::value_type(100,100));

		//traversal
        map<int, int>::iterator it;
        for (it = mp.begin(); it != mp.end(); it++){
                printf("%d-->%d
", it->first, it->second);
        }

        return 0;
}
原文地址:https://www.cnblogs.com/muahao/p/8808376.html