源代码如下,附带详细的解释
参考:http://blog.csdn.net/wschli/article/details/39379193
#include <iostream>
using namespace std;
#include <map>
#include <string>
#include <iostream>
class OBJ
{
public:
OBJ(int n)
{
num = n;
}
int getNum()
{
return num;
}
private:
int num;
};
int main()
{
using namespace std;
typedef map<std::string,OBJ> ObjList;
ObjList mObj;
OBJ obj(1);
mObj.insert(make_pair("str",obj));
ObjList mObj2;
ObjList::iterator it = mObj.begin();
std::cout<<"mObj-"<<endl;
for(it;it != mObj.end();it++)
{
mObj2.insert(make_pair(it->first,it->second));
std::cout<<"str:"<<it->first<<endl;
std::cout<<"num:"<<it->second.getNum()<<endl;
}
ObjList::iterator it2 = mObj2.begin();
std::cout<<"mOjb2-"<<endl;
for(it2;it2 != mObj2.end();it2++)
{
std::cout<<"str:"<<it2->first<<endl;
std::cout<<"num:"<<it2->second.getNum()<<endl;
}
return 0;
}