当前位置: 首页 > news >正文

list与流迭代器stream_iterator

运行代码:

//list与流迭代器
#include"std_lib_facilities.h"
//声明Item类
struct Item
{string name;int iid;double value;Item():name(" "),iid(0),value(0.0){}Item(string ss,int ii,double vv):name(ss),iid(ii),value(vv){}friend istream& operator>>(istream& is, Item& ii);friend ostream& operator<<(ostream& os, const Item& ii);};//------------------------------------------------------------
//重载Item类的输入和输出操作符
istream& operator>>(istream& is, Item& ii)
{is >> ii.name >> ii.iid >> ii.value;return is;
}ostream& operator<<(ostream& os, const Item& ii)
{os << ii.name << " " << ii.iid << " " << ii.value;return os;
}//----------------------------------------------------------int main()
try
{cout << "输入读取文件名: ";string from_file;cin >> from_file;ifstream is(from_file.c_str());if (!is)error("can't open ", from_file);istream_iterator<Item>ii(is);istream_iterator<Item>eos;ostream_iterator<Item>oo(cout, "\n");list<Item>ll(ii, eos);copy(ll.begin(), ll.end(), oo);return 0;
}
catch (exception& e) {cerr << "error:" << e.what() << '\n';keep_window_open();return 1;
}
catch (...) {cerr << "Oops:unknown exception!\n";keep_window_open();return 2;
}

读取文件:Item_file.txt

Max 2 43.2
Jane 3 34.2
Tom 3 32.4
Mary 8 23.0
Peter 5 32.5
Max 2 43.2
Jane 3 34.2
Tom 3 32.4
Mary 8 23.0
Peter 5 32.5
 

运行结果:

http://www.lryc.cn/news/100987.html

相关文章:

  • 九耶:冯·诺伊曼体系
  • 探索UCI心脏病数据:利用R语言和h2o深度学习构建预测模型
  • 基于 moleculer 微服务架构的智能低代码PaaS 平台源码 可视化开发
  • xrdp登录显示白屏且红色叉
  • Docker安装 Mysql 8.x 版本
  • 【数理知识】刚体 rigid body 及刚体的运动
  • 【UE5 多人联机教程】03-创建游戏
  • 【时间序列预测 】M4
  • SpringCloud微服务实战——搭建企业级开发框架(五十三):微信小程序授权登录增加多租户可配置界面
  • Stability AI推出Stable Diffusion XL 1.0,文本到图像模型
  • B076-项目实战--宠物上下架 展示 领养 收购订单
  • 【iOS】—— 持久化
  • 教程 - 在 Vue3+Ts 中引入 CesiumJS 的最佳实践@2023
  • 最优化方法
  • Mongodb 多文档聚合操作处理方法二(Map-reduce 函数)
  • ant design vue j-modal 修改高度
  • spring学习笔记七
  • hw技战法整理参考
  • uniapp 全局数据(globalData)的设置,获取,更改
  • Profinet转EtherNet/IP网关连接AB PLC的应用案例
  • Python组合模式介绍、使用方法
  • 生成模型和判别模型工作原理介绍
  • shardingsphere读写分离配置
  • 登录报错 “msg“:“Request method ‘GET‘ not supported“,“code“:500
  • Python 日期和时间
  • pytorch的发展历史,与其他框架的联系
  • Kibana-elastic--Elastic Stack--ELK Stack
  • Docker复杂命令便捷操作
  • Python中的datetime模块
  • Flutter - 微信朋友圈、十字滑动效果(微博/抖音个人中心效果)