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

你可能感兴趣的文章
mysql索引
查看>>
Mysql索引,索引的优化,如何避免索引失效案例
查看>>
Mysql索引、命令重点介绍
查看>>
mysql索引、索引优化(这一篇包括所有)
查看>>
Mysql索引一篇就够了
查看>>
MySQL索引一篇带你彻底搞懂(一次讲清实现原理加优化实战,面试必问)
查看>>
MySQL索引下沉:提升查询性能的隐藏秘
查看>>
MySql索引为什么使用B+树
查看>>
MySQL索引为什么是B+树
查看>>
WARNING!VisualDDK wizard was unable to find any DDK/WDK installed on your system.
查看>>
MySQL索引介绍及百万数据SQL优化实践总结
查看>>
Mysql索引优化
查看>>
MySQl索引创建
查看>>
mysql索引创建及使用注意事项
查看>>
mysql索引创建和使用注意事项
查看>>
MySQL索引原理以及查询优化
查看>>
Mysql索引合并(index merge)导致的死锁问题
查看>>
MySQL索引和查询优化
查看>>
mysql索引底层数据结构和算法
查看>>
Mysql索引底层结构的分析
查看>>