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\n");
		} else {
			printf("no\n");
		}

		//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\n");
		}

		//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\n", it->first, it->second);
        }

        return 0;
}
posted @ 2018-04-12 16:11  苏小北1024  阅读(337)  评论(0编辑  收藏  举报