cpp打印map的键和值

#include
#include
using namespace std;

int main() {
	map mp;
	mp['m'] = 20;
	mp['r'] = 30;
	mp['a'] = 40;
	for (map::iterator it = mp.begin();
		it != mp.end(); it++) {
		printf("%c %d\n", it->first, it->second);
	}

	return 0;
}
a 40
m 20
r 30

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