博客
关于我
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笔记:InnoDB的锁机制
查看>>
mysql第一天~mysql基础【主要是DDL、DML、DQL语句,以及重点掌握存存引擎、查询(模糊查询)】
查看>>
mysql第二天~mysql基础【查询排序、分页查询、多表查询、数据备份与恢复等】
查看>>
MySQL简介和安装
查看>>
MySQL简单查询
查看>>
MySQL管理利器 MySQL Utilities 安装
查看>>
MySQL篇(管理工具)
查看>>
mysql类型转换函数convert与cast的用法
查看>>
mysql系列一
查看>>
MySQL系列之数据授权(安全)
查看>>
MySQL系列之数据类型(Date&Time)
查看>>
MySQL系列之数据类型(Date&Time)
查看>>
Mysql系列之锁机制
查看>>
Mysql系列九:使用zookeeper管理远程Mycat配置文件、Mycat监控、Mycat数据迁移(扩容)...
查看>>
MySql系列:[4200][1140]In aggregated query without GROUP BY, expression #2 of SELECT list contains nona
查看>>
MySQL索引
查看>>
Mysql索引
查看>>
mysql索引
查看>>
mysql索引
查看>>