C++primer 10.4.2节练习

练习10.29

 1 #include<iostream>
 2 #include<string>
 3 #include <iostream>
 4 #include <string>
 5 #include <vector>
 6 #include <algorithm>
 7 #include <list>
 8 #include <functional>
 9 #include <iterator>
10 #include <fstream>
11 using namespace std;
12 using namespace placeholders;
13 
14 
15 int main()
16 {
17     vector<string> vec;
18     ifstream in("title.txt");
19     istream_iterator<string> inFile(in);
20     istream_iterator<string> eof;
21     ostream_iterator<string> out_file(cout, " ");
22     while (inFile != eof)
23     {
24         vec.push_back(*(inFile++));
25     }
26     for (auto c : vec)
27         out_file = c;
28     cout << endl;
29     system("pause");
30     return 0;
31 }

练习10.30

 1 #include<iostream>
 2 #include<string>
 3 #include <iostream>
 4 #include <string>
 5 #include <vector>
 6 #include <algorithm>
 7 #include <list>
 8 #include <functional>
 9 #include <iterator>
10 #include <fstream>
11 using namespace std;
12 using namespace placeholders;
13 
14 
15 int main()
16 {
17     vector<int> num;
18     istream_iterator<int> num_cin(cin);
19     istream_iterator<int> eof;
20     ostream_iterator<int> out_file(cout, " ");
21     while (num_cin != eof)
22     {
23         num.push_back(*num_cin++);
24     }
25     sort(num.begin(), num.end());
26     copy(num.begin(), num.end(), out_file);
27     cout << endl;
28     system("pause");
29     return 0;
30 }

练习10.31

 1 #include<iostream>
 2 #include<string>
 3 #include <iostream>
 4 #include <string>
 5 #include <vector>
 6 #include <algorithm>
 7 #include <list>
 8 #include <functional>
 9 #include <iterator>
10 #include <fstream>
11 using namespace std;
12 using namespace placeholders;
13 
14 
15 int main()
16 {
17     vector<int> num;
18     vector<int> num1;
19     istream_iterator<int> num_cin(cin);
20     istream_iterator<int> eof;
21     ostream_iterator<int> out_file(cout, " ");
22     while (num_cin != eof)
23     {
24         num.push_back(*num_cin++);
25     }
26     sort(num.begin(), num.end());
27     unique_copy(num.begin(), num.end(), back_inserter(num1));
28     copy(num1.begin(), num1.end(), out_file);
29     cout << endl;
30     system("pause");
31     return 0;
32 }

 

练习10.32

自己写的程序有错,需要修改,稍后上传

练习10.33

 1 #include<iostream>
 2 #include<string>
 3 #include <iostream>
 4 #include <string>
 5 #include <vector>
 6 #include <algorithm>
 7 #include <list>
 8 #include <functional>
 9 #include <iterator>
10 #include <fstream>
11 using namespace std;
12 using namespace placeholders;
13 
14 void unraval(ifstream &in, ofstream &out1, ofstream &out2);
15 
16 int main()
17 {
18     ifstream in("test1.txt");
19     ofstream out1("test2.txt", ofstream::app);
20     ofstream out2("test3.txt", ofstream::app);
21     unraval(in, out1, out2);
22     system("pause");
23     return 0;
24 }
25 
26 void unraval(ifstream &in, ofstream &out1, ofstream &out2)
27 {
28     istream_iterator<int> inFile(in), eof;
29     ostream_iterator<int> out_file1(out1, "  ");
30     ostream_iterator<int> out_file2(out2, "\n");
31     while (inFile != eof)
32     {
33         if ((*inFile) % 2 != 0)
34             out_file1 = *inFile++;
35         else
36             out_file2 = *inFile++;
37     }
38 }

 

转载于:https://www.cnblogs.com/wuyinfenghappy/p/7360382.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值