1 // chapter17.h
2
3 #ifndef LEARN_CPP_CHAPTER17_H
4 #define LEARN_CPP_CHAPTER17_H
5
6 #include <iostream>
7 #include <fstream>
8 #include <vector>
9 #include <algorithm>
10 #include <cstring>
11
12 void ch17_1();
13 void ch17_2(const std::string filename);
14 void ch17_3(const std::string infilename, const std::string outfilename);
15 void ch17_4(const std::string infilename1, const std::string infilename2, const std::string outfilename);
16 void ch17_5(const std::string matfile, const std::string patfile, const std::string matnpatfile);
17 void ch17_6();
18 void ShowStr(const std::string & str);
19 void GetStrs(std::ifstream & fin, std::vector<std::string> & vistr);
20 void ch17_7();
21
22 class Store {
23 private:
24 char * str;
25 std::ofstream * outf;
26 public:
27 Store(std::ofstream & fout) : outf(&fout) {
28 str = new char[1024];
29 }
30 Store(const Store & s) {
31 if (this == &s)
32 delete [] str;
33 str = new char[1024];
34 strcpy(str, s.str);
35 outf = s.outf;
36 }
37 bool operator()(const std::string & s) {
38 int len = s.size();
39 if (outf->is_open()) {
40 outf -> write((char *)&len, sizeof(int));
41 outf -> write(s.data(), len);
42 return true;
43 }
44 else {
45 exit(EXIT_FAILURE);
46 return false;
47 }
48 }
49 };
50
51
52 #endif //LEARN_CPP_CHAPTER17_H
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 »
编程练习答案——第17章