代码:
/*
*Copyright (c) 2016, 烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:main.cpp;
*作 者:岳成艳 2016年6月9号;
*版 本 号:vc++6.0;
*
*问题描述:。
*程序输入:略;
*程序输出:略;
*/
#include<iostream>
#include<string>
#include<map>
using namespace std;
class CStudent
{
public:
int nStudentID;
int nAge;
public:
CStudent() {}
CStudent(int nSID,int nA)
{
nStudentID=nSID;
nAge=nA;
}
//复制构造函数
CStudent(const CStudent& ob)
{
nStudentID=ob.nStudentID ;
nAge=ob.nAge ;
}
};
int main()
{
map<string,CStudent>mapStudent;
mapStudent["zhangsan"]=CStudent(100012,22);
mapStudent["lisi"]=CStudent(100085,21);
mapStudent["wangwu"]=CStudent(100093,23);
cout<<"The Student number for lisi is "<<(mapStudent["lisi"].nStudentID)<<endl;
return 0;
}
运行测试:
知识点总结:
运用STL,复制构造函数。