C++primer(第五版)8.2.2节练习答案
2015-02-11 14:01
309 查看
练习8.7:修改上一节的书店程序,将结果保存到一个文件中。将输出文件名作为第二个参数传递给main函数。
解答:
练习8.8:修改上一题的程序,将结果追加到给定的文件末尾。对同一个输出文件,运行程序至少两次,检验数据是否得以保留。
解答:
解答:
#include<iostream> #include<fstream> #include<../ch07/ex7_26.h> using std::ofstream;using std::endl;using std::ifstream;using std::cerr; int main(int argc,char **argv) { ifstream input(argv[1]); ofstream output(argv[2]); Sales_data total; if(read(input,total)) { Sales_data trans; while(read(input,trans)) { if(total.isbn() == trans.isbn()) total.combine(trans); else { printf(output,total)<<endl; total = trans; } } printf(output,total)<<endl; } else { cerr<<"No data?!"<<endl; } return 0; }
练习8.8:修改上一题的程序,将结果追加到给定的文件末尾。对同一个输出文件,运行程序至少两次,检验数据是否得以保留。
解答:
#include<iostream> #include<fstream> #include<../ch07/ex7_26.h> using std::ofstream;using std::endl;using std::ifstream;using std::cerr; int main(int argc,char **argv) { ifstream input(argv[1]); ofstream output(argv[2],ofstream::app); Sales_data total; if(read(input,total)) { Sales_data trans; while(read(input,trans)) { if(total.isbn() == trans.isbn()) total.combine(trans); else { printf(output,total)<<endl; total = trans; } } printf(output,total)<<endl; } else { cerr<<"No data?!"<<endl; } return 0; }
相关文章推荐
- C++primer(第五版)8.2.2节练习答案
- c++primer第五版课后练习答案(第一章)
- c++primer第五版课后练习答案(第五章)
- c++primer第五版课后练习答案(第十章)
- C++primer(第五版)9.3.4节,9.3.5节,9.3.6节练习答案
- C++primer(第五版)9.1节,9.2节,9.2.1节练习答案
- C++primer(第五版)9.2.2节,9.2.3节,9.2.4节练习答案
- C++primer(第五版)9.4节练习答案
- 从今天开始,把C++primer(第五版)的课后练习答案贴到我的博客里面
- c++primer第五版课后练习答案(第六章)
- C++primer(第五版)9.5.1节,9.5.2节,9.5.3节,9.5.5节,9.6节练习答案
- C++primer(第五版)9.2.5节,9.2.7节练习答案
- C++primer(第五版)9.3.1节,9.3.2节,9.3.3节练习答案
- C++Primer第五版 8.2.2节练习
- C++primer(第五版)8.3.2节练习答案
- C++Primer第五版 第十五章习题答案(21~30)
- C++Primer第五版 第十五章习题答案(31~40)
- C++primer第五版 练习5.14
- C++Primer第五版 第十六章习题答案(11~20)
- c++primer第五版 练习5.20