博客
关于我
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/

你可能感兴趣的文章
memcache、redis原理对比
查看>>
memset初始化高维数组为-1/0
查看>>
Metasploit CGI网关接口渗透测试实战
查看>>
Metasploit Web服务器渗透测试实战
查看>>
MFC模态对话框和非模态对话框
查看>>
Moment.js常见用法总结
查看>>
MongoDB出现Error parsing command line: unrecognised option ‘--fork‘ 的解决方法
查看>>
mxGraph改变图形大小重置overlay位置
查看>>
MongoDB可视化客户端管理工具之NoSQLbooster4mongo
查看>>
Mongodb学习总结(1)——常用NoSql数据库比较
查看>>
MongoDB学习笔记(8)--索引及优化索引
查看>>
mongodb定时备份数据库
查看>>
mppt算法详解-ChatGPT4o作答
查看>>
mpvue的使用(一)必要的开发环境
查看>>
MQ 重复消费如何解决?
查看>>
mqtt broker服务端
查看>>
MQTT 保留消息
查看>>
MQTT 持久会话与 Clean Session 详解
查看>>
MQTT介绍及与其他协议的比较
查看>>
MQTT工作笔记0007---剩余长度
查看>>