list7-18.cpp

来自「这是关于VC++中的STL容器的资料,包括了STL容器各个类之间关系以及类的说明」· C++ 代码 · 共 40 行

CPP
40
字号
// Listing 7-18
// This program demonstrates how a map collection can
// be initialized using the insert method and subsript
// operator.


#include<string>
#include<map>
#include<iostream>
#include <vector>

using namespace std;


	
pair<string,string> Object1("122.22.33.45","www.example1.map");
pair<string,string> Object2("122.33.44.55","www.example2.map");
pair<string,string> Object3("122.33.55.66","www.example3.map");
vector<pair<string,string> > Group;
pair<string,string> Temp;


void main(void)
{
	Group.push_back(Object1);
	Group.push_back(Object2);
	Group.push_back(Object3);
	map<string,string,less<string> > MapA;
   MapA.insert(Group.begin(),Group.end());
   MapA["122.77.66.77"] = "www.example4.map";
 	map<string,string,less<string> >::iterator P = MapA.begin();
	while(P != MapA.end())
	{
 	     Temp = *P;
	     cout << "The key   for MapA is " << Temp.first << endl;
	     cout << "The value for MapA is " << Temp.second << endl;
	     P++;
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?