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

你可能感兴趣的文章
MSSQL数据库查询优化(一)
查看>>
MSSQL数据库迁移到Oracle(二)
查看>>
MSSQL日期格式转换函数(使用CONVERT)
查看>>
MSTP多生成树协议(第二课)
查看>>
MSTP是什么?有哪些专有名词?
查看>>
Mstsc 远程桌面链接 And 网络映射
查看>>
Myeclipse常用快捷键
查看>>
MyEclipse更改项目名web发布名字不改问题
查看>>
MyEclipse用(JDBC)连接SQL出现的问题~
查看>>
mt-datetime-picker type="date" 时间格式 bug
查看>>
myeclipse的新建severlet不见解决方法
查看>>
MyEclipse设置当前行背景颜色、选中单词前景色、背景色
查看>>
Mtab书签导航程序 LinkStore/getIcon SQL注入漏洞复现
查看>>
myeclipse配置springmvc教程
查看>>
MyEclipse配置SVN
查看>>
MTCNN 人脸检测
查看>>
MyEcplise中SpringBoot怎样定制启动banner?
查看>>
MyPython
查看>>
MTD技术介绍
查看>>
MySQL
查看>>