仅仅作个人笔记
#include <cstdio>
#include <iostream>
#include <string>
#include <map>
#include <algorithm> //find头文件
#include <memory> //make_shared头文件
using namespace std;
class student
{
public:
string father;
string mother;
};
int main()
{
map<string, shared_ptr<student>> ptl;
shared_ptr<student> pt = make_shared<student>();
pt->father = "张二";
ptl.emplace("张三", pt);
cout << ptl["张三"]->father << endl;
cout << ptl.at("张三")->father << endl;
auto iter = ptl.find("张三");
if (iter == ptl.end())
{
cout << "未找到此键值" << endl;
}
else
{
cout << iter->first << endl;
cout << iter->second->father << endl;
}
return 0;
}
运行结果:
张二
张二
张三
张二