64,646
社区成员
发帖
与我相关
我的任务
分享
/************************************************************************/
/* pair对象的创建和使用 */
/************************************************************************/
#include <iostream>
#include <utility>
#include <map>
#include <string.h>
using namespace std;
class Student
{
public:
Student()
{
strcpy(m_sName, "NULL");
m_nAge = 0;
}
Student(char sName[20], int nAge)
{
strcpy(m_sName ,sName);
m_nAge = nAge;
}
Student(Student& s1)
{
strcpy(m_sName, s1.GetName());
m_nAge = s1.GetAge();
}
int GetAge()
{
return m_nAge;
}
char * GetName()
{
return m_sName;
}
private:
char m_sName[20];
unsigned int m_nAge;
};
int main()
{
Student s1("sdd",3);
map<int, Student> m1;
m1.insert(pair<int, Student>(12, s1) );
return 0;
}
char * GetName() const
{
return m_sName;
}
class Student
{
public:
Student()
{
strcpy(m_sName, "NULL");
m_nAge = 0;
}
Student(int a)
{
m_nAge = a;
}
Student(const char*sName, int nAge)
{
strcpy(m_sName ,sName);
m_nAge = nAge;
}
Student(const Student& s1)
{
strcpy(m_sName, s1.m_sName);
m_nAge = s1.m_nAge;
}
int GetAge()
{
return m_nAge;
}
char * GetName()
{
return m_sName;
}
private:
char m_sName[20];
unsigned int m_nAge;
};
int main()
{
// Student s1;
map<int, Student> m1;
m1.insert(pair<int,Student>(12, Student("lilin", 3)) );
system("pause");
return 0;
}
int GetAge() const
{
return m_nAge;
}
char * GetName() const
{
return m_sName;
}
/************************************************************************/
/* pair对象的创建和使用 */
/************************************************************************/
#include <iostream>
#include <utility>
#include <map>
#include <string.h>
using namespace std;
class Student
{
public:
Student()
{
strcpy(m_sName, "NULL");
m_nAge = 0;
}
Student(int a)
{
m_nAge = a;
}
Student(char sName[20], int nAge)
{
strcpy(m_sName ,sName);
m_nAge = nAge;
}
Student(const Student& s1)
{
strcpy(m_sName, s1.GetName());
m_nAge = s1.GetAge();
}
int GetAge()
{
return m_nAge;
}
char * GetName()
{
return m_sName;
}
private:
char m_sName[20];
unsigned int m_nAge;
};
int main()
{
Student s1;
map<int, Student> m1;
m1.insert(pair<int, Student>(12, s1("lilin", 3)) );
return 0;
}