1. 程式人生 > >vector map 多層巢狀使用

vector map 多層巢狀使用

#include <vector>
#include <map>

using namespace std;
typedef vector<int>			vectTemp;
typedef map<int,vectTemp>	mapTemp;
typedef map<int,mapTemp>	MapM;


void main()
{	
	vectTemp vectInt;
	mapTemp  mapVect;
	MapM	 mapMap;
	vectInt.push_back(1);
	mapVect[1] = vectInt;
	mapMap[1] = mapVect;
	printf("%d\n",vectInt[0]);
	printf("%d\n",mapVect[1][0]);
	printf("%d\n", mapMap[1][1][0]);
	mapMap[2][2].push_back(10);
	printf("%d\n", mapMap[2][2][0]);
	system("pause");
}




注意的是,vector訪問未賦值的下標會越界,map訪問未賦值的下標會建立一個新的並設定為0