【C++ Primer Plus】编程练习答案——第17章

 1 // chapter17.h
 2 
 3 #ifndef LEARN_CPP_CHAPTER17_H
 4 #define LEARN_CPP_CHAPTER17_H
 5 
 6 #include 
 7 #include 
 8 #include 
 9 #include 
10 #include 
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::vectorstring> & 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

新闻名称:【C++ Primer Plus】编程练习答案——第17章
文章源于:http://myzitong.com/article/dsogohc.html