博客
关于我
STL常用运算符重载
阅读量:302 次
发布时间:2019-03-03

本文共 924 字,大约阅读时间需要 3 分钟。

bool operator<(const Person& p)const //小于运算符

friend ostream& operator<<(ostream& os,const Person& p1) //输出

#include
#include
#include
#include
using namespace std;class Person{ public: Person(string name, string no, int age) { this->sname = name; this->sno = no; this->sage = age; } bool operator<(const Person& p)const { if (this->sno < p.sno) return true; return false; } friend ostream& operator<<(ostream& os,const Person& p1) { cout << "姓名:" << p1.sname << " 学号:" << p1.sno << " 年龄:" << p1.sage << endl; return os; }public: string sname; string sno; int sage;};int main(){ Person p3("王麻子", "18170025", 18); Person p1("张三", "18170021", 19); Person p2("李四", "18170022", 20); set
st; st.insert(p2); st.insert(p1); st.insert(p3); set
::iterator it; for (it = st.begin(); it != st.end(); it++) cout << *it; system("pause"); return 0;}

转载地址:http://vksm.baihongyu.com/

你可能感兴趣的文章
new Blob()实现不同类型的文件下载功能
查看>>
New Concept English three (35)
查看>>
NEW DATE()之参数传递
查看>>
New Journey--工作五年所思所感小记
查看>>
new Queue(REGISTER_DELAY_QUEUE, true, false, false, params)
查看>>
New Relic——手机应用app开发达人的福利立即就到啦!
查看>>
new work
查看>>
new 一个button 然后dispose,最后这个button是null吗???
查看>>
NewspaceGPT的故事续写能力太强了
查看>>
NewspaceGPT绘制时序图
查看>>
NewspaceGPT绘制类图
查看>>
new一个对象的过程
查看>>
new和delete用法小结
查看>>
new对象时,JVM内部究竟藏了什么小秘密?
查看>>
new操作符的实现原理
查看>>
Next.js React Server Components 教程
查看>>
NextGen Mirth Connect XStream反序列化远程代码执行漏洞(CVE-2023-43208)
查看>>
next项目部署到服务器pm2进程守护
查看>>
nexus 介绍
查看>>
nexus上传jar
查看>>