C++ STL 第四次实验
来源:互联网 发布:淘宝免费申请试用手机 编辑:程序博客网 时间:2024/06/03 18:18
从billionaires中找到中国38~45岁的亿万富翁!
billionaires.bin来源是福布斯网页
billion.bin是struct billion的2进制存储,billion的定义为:
struct billion {
int no;
char name[20];
char account[6];
int age;
char company[20];
char country[20];
};
要求内容:
1、读取2进制文件,形成一个vector的容器内容。
2、使用for_each遍历vector容器内所有元素,调用find_billion(“China”, 38, 45),打印出满足要求的所有富翁。
billion.bin文件放不上来,需要的可以加我的QQ:739444364,不懂得也可以问
#include <iostream>#include <fstream>#include <algorithm>#include <vector>#include <string.h>using namespace std;struct billion{ int no; char name[20]; char account[6]; int age; char company[20]; char country[20];};class find_billion{private: billion b; char* country; int min; int max;public: find_billion(){ memset(this->country,NULL,sizeof(this->country)); min = 0; max = 0; } find_billion(char *country,int min,int max){ this->country = country; this->min = min; this->max = max; } void operator()(billion b){ if(min<b.age<max && !strcmp(b.country,country)){ cout << b.no << "\n"; cout << b.name << "\n"; cout << b.account << "\n"; cout << b.age << "\n"; cout << b.company << "\n"; cout << b.country << "\n"; } }};int main(){ ifstream in; in.open("billion.bin",ios::binary); vector<billion>v; billion b; in.read((char*)&b,sizeof(billion)); while(!in.eof()){ in.read((char*)&b,sizeof(billion)); v.push_back(b); } find_billion bil = for_each(v.begin(),v.end(),find_billion("China",38,45)); in.close();}
阅读全文
2 0
- C++ STL 第四次实验
- C++STL 第八次实验
- 第四次C程序设计实验报告
- 第四次c语言上机实验报告
- 第四次C语言上机实验报告
- 第四次上机实验
- 第四次上机实验
- 第四次上机实验
- 第四次实验报告
- 第四次上机实验
- 第四次上机实验
- 第四次上机实验
- 第四次上机实验
- 第四次实验任务
- 第四次实验报告
- 第四次上机实验
- 第四次上机实验
- 第四次实验任务
- 连接阿里云数据库redis版 超时问题
- LVM
- Mysql Multi-Range Read
- ffmpeg开发之旅(1):视频直播YUV颜色格式完全解析
- ios开发之小总结「类与对象的判断方法和遍历字典的方法」
- C++ STL 第四次实验
- swiper 不能new 成功
- iOS中MVC设计模式
- (Windows)Mysql设置远程连接,授权
- 大数据企业学习篇01之---Linux的那些事
- ffmpeg开发之旅(2):深度解析H.264编码原理
- mongo查询优化
- linux/unix多线程/多进程编程总结(二)
- linux驱动学习之kthread_work和kthread_worker机制