|
|

楼主 |
发表于 2005-5-19 12:25:00
|
显示全部楼层
方法1和方法2都符合STL语法,但只有方法2可以在vc 6.0 + sp5
// --- Test prog: map_pair_t.cpp --- //
#include <iostream>
#include <map>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
typedef map<string,string> StrStrMap;
StrStrMap TextureMap; // create empty container
// --- 方法1
TextureMap.insert(make_pair("Boar","BoarSkinBlue.blp"));
TextureMap.insert(make_pair("AirElemental","AirElementalSkin.blp"));
// --- 方法2
//TextureMap["Boar"] = "BoarSkinBlue.blp";
//TextureMap["AirElemental"] = "AirElementalSkin.blp";
// print all elements
StrStrMap::iterator pos;
cout.setf (ios::left, ios::adjustfield);
cout << ' ' << setw(15) << "ModelName " << "TexName " << endl;
cout << setfill('-') << setw(55) << "" << setfill(' ') << endl;
for (pos = TextureMap.begin(); pos != TextureMap.end(); ++pos) {
cout << ' ' << setw(15) << pos->first << pos->second << endl;
}
cout << endl;
}
|
|