文件 1.cc

#include <string>
#include <iostream>
#include <fstream>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
using namespace std;
void print_(map<string,vector<pair<string,string>>> &f);
int main(int argc,char **argv)
{
map<string,vector<pair<string,string>>> family;string surname;
string name;
string birthday;ifstream in(argv[1]);if(!in){cout <<"no file." <<endl;exit(EXIT_FAILURE);}while(in >> surname && in >> name && in >> birthday)
{family[surname].push_back({name,birthday});
}
print_(family);return 0;}
void print_(map<string,vector<pair<string,string>>> &f)
{
for(auto & i : f){cout << i.first << endl;for(auto & j : i.second){cout << "\tname:" << j.first <<endl;cout << "\tbirthday:" << j.second << endl;}    }}

文件family.txt

乔 乔大愣 19840926
乔 乔二愣 20180722
王 王东   1111111
白 白色荒漠 123456

在linux g++编译器下编译(如果centos 还得加 -std=c++11):

 g++ 4.cc -o f

运行:

username$ ./f family.txt
乔name:乔大愣birthday:19840926name:乔二愣birthday:20180722
王name:王东birthday:1111111
白name:白色荒漠birthday:123456

c++ primer 5th 习题11.14自己编写的答案相关推荐

  1. c++ primer 5th ,习题11.23自己编写答案

    第一部分:自己编写的程序: #include <string> #include <iostream> #include <map> #include <fs ...

  2. c++ primer 5th 练习11.9自己编写的答案

    #include <string> #include <iostream> #include <list> #include <vector> #inc ...

  3. c++ primer 5th,练习11.19,编写代码验证

    对于这个题,自己话费2个多小时编写了代码,亲自验证正确性,顺便复习类的知识点,下面采用分离式编译自己把代码放在三个文件中main.cc,function,sales_data.h,大家应该根据文件名推 ...

  4. c++ primer 5th 练习11.38自己编写答案(用无序容器重写单词计数程序)

    文件main.cc #include <string> #include <iostream> #include <unordered_map> #include ...

  5. c++primer 5th习题12.25答案

    #include <memory> #include <cstdlib> using namespace std; int main() { char *p = new cha ...

  6. c++ primer 5th第13章拷贝控制知识点和自编习题答案

    首先,先给大家提个醒.在网上的随书源代码里关于hasptr类的类指针版本编写的移动构造函数.移动赋值运算符.和析构函数部分是有错误的.大家可以把hasptr累指针版本(里面带移动构造函数和移动赋值运算 ...

  7. C++ Primer - 5th Edition - 书中源代码 - 课后习题答案

    C++ Primer - 5th Edition - 书中源代码 - 课后习题答案 C++ Primer - 5th Edition - 书中源代码 - 课后习题答案 1. C++ Primer, 5 ...

  8. c++ primer 5th,习题13.3 答案是不是错了?(未解决)

    c++ primer 5th,习题13.3 答案是不是错了?如下: 这两个类都未定义拷贝构造函数,因此编译器为它们定义了合成的拷贝构造函数.合成的拷贝构造函数逐个拷贝非 const成员,对内置类型的成 ...

  9. 《C++ Primer 5th》笔记(9 / 19):顺序容器

    文章目录 顺序容器概述 确定使用哪种顺序容器 容器库概览 迭代器 迭代器范围 使用左闭合范围蕴含的编程假定 容器类型成员 begin和end成员 容器定义和初始化 将一个容器初始化为另一个容器的拷贝 ...

最新文章

  1. MYSQL中如何查看表结构命令_mysql查看表结构命令
  2. C#向C++编写的DLL传递字符串参数的办法
  3. 源代码提交SOP(Git版)
  4. seclists各种字典工具
  5. 【Python】Python库之数据分析
  6. Oracle锁表处理
  7. es分页查询重复数据_ES优化 - 巨量数据如何提高查询性能
  8. 中国历史上最牛气的十大豪言壮语
  9. python辗转相除法求最小公倍数_Python实现利用最大公约数求三个正整数的最小公倍数示例...
  10. java发送qq邮件
  11. 降级至1.1.835教程
  12. GPC凝胶色谱理论和应用(三)
  13. 浏览器被流氓软件修改了主页怎么办?
  14. 3D MAX 插件的基本知识和安装方法
  15. PHPMYSQL物联网监控系统Web端
  16. 黑马python培训_要一张纯黑的图片。纯黑的。
  17. 语音怎么在线转文字,语音转文字的小技巧
  18. 关于熔断器Hystrix替代方案的调研报告
  19. 改装普通电脑为触屏电脑
  20. Bootstrap栅格布局

热门文章

  1. MySQL数据库服务器 主从配置
  2. [基础题]2.(*)利用接口做参数,写个计算器,能完成加减乘除运算。
  3. 解决sublime3 中文乱码问题
  4. 操作系统实验报告13:线程池简单实现
  5. C# 基础知识 (三).主子对话框数值传递
  6. ☆ 10个小技巧,让你的 Python 代码更加优雅~ ☆
  7. 2013\Province_Java_C\2.组素数
  8. 信息学奥赛一本通(C++)在线评测系统——基础(一)C++语言——1103:陶陶摘苹果
  9. 【Notes7】Samba/NFS服务器,Ntp,导出log,modprobe,进入ME刷bios,树莓派
  10. 【C/C++16】_public.h,_public.cpp,_cmpublic.h