C++中map自定义value

网友投稿 221 2022-08-23

C++中map自定义value

仅仅作个人笔记

#include #include #include #include #include //find头文件#include //make_shared头文件using namespace std;class student{public: string father; string mother;};int main(){ map> ptl; shared_ptr pt = make_shared(); 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;}

运行结果:

张二张二张三张二

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:医药营销的“黄埔军校”,也没能跑赢时代!(医药业内最早的黄埔军校)
下一篇:Java多级菜单树转为面包屑
相关文章

 发表评论

暂时没有评论,来抢沙发吧~