cpp的map.find(key)函数

#include
#include
using namespace std;

int main() {
	/*
	map.find(key)返回键为key的映射的迭代器
	*/
	map mp;
	mp['m'] = 20;
	mp['r'] = 30;
	mp['a'] = 40;
	map::iterator it = mp.find('a');
	if (it !=mp.end()){
		printf("%c %d\n", it->first,it->second);
	}
	else {
		printf("没找到\n");
	}
	


	return 0;
}

你可能感兴趣的:(c++数据结构)