re: 模板套模板~~ 红叶搂风 2006-04-07 17:59
#include <iostream>
#include <map>
#include <string>
using std::map;
using std::cout;
using std::endl;
using std::string;
template<class T1,class T2>
void PrintMap(map<T1,T2 >& maptemp,string tempstr = "")
{
cout<<tempstr
<<endl;
typename map<T1,T2 >::const_iterator pos;
for (pos = maptemp.begin();pos != maptemp.end();++pos) {
cout<<"map["
<<pos->first
<<"]="
<<pos->second
<<" ";
}
}
int main(void)
{
map<string,int> map1;
map<string,map<string,int> > map2;
map1["string"] = 2;
map2["string2"] = map1;
PrintMap<string,int>(map1,"map1");
return 0;
}