c++ map的使用--键值对的集合

#include <iostream>
#include <map>

using namespace std;

int main()
{
	map<int, string> m;
	m[0] = "h1";
	m[3] = "what";
	m.insert(pair<int, string>(4, "love you"));

	cout<<m[0].c_str()<<endl;
	cout<<m[3].c_str()<<endl;
	cout<<m[4].c_str()<<endl;
	cout<<m[2].c_str()<<endl;	// 会产生一个新的元素,即m[2] = ""


	cout<<m.size()<<endl;		// 4

	for(map<int, string>::iterator it = m.begin(); it != m.end(); it++)
	{
		cout<<it->first<<", "<<it->second.c_str()<<endl;
	}
	

	return 0;
}

上面的代码在vc.net2005下没有一个warning,但是在vc6下却有94个warning,不知为何?

原文地址:https://www.cnblogs.com/joeblackzqq/p/1966579.html