-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12.1.2.cc
55 lines (42 loc) · 938 Bytes
/
12.1.2.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <vector>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <memory>
using namespace std;
void input(vector<int> * ivec){
istream_iterator<int> in(cin);
istream_iterator<int> eof;
copy(in, eof, back_inserter(*ivec));
}
void print(vector<int> * ivec){
ostream_iterator<int> out(cout, " ");
for(auto & i : *ivec)
out = i;
delete ivec;
}
void test1(){
vector<int> * p(new vector<int>());
input(p);
print(p);
}
void input2(shared_ptr<vector<int>> p){
istream_iterator<int> in(cin);
istream_iterator<int> eof;
copy(in, eof, back_inserter(*p));
}
void print2(shared_ptr<vector<int>> p){
ostream_iterator<int> out(cout, " ");
for(auto & i : *p)
out = i;
}
void test2(){
shared_ptr<vector<int>> p = make_shared<vector<int>>();
input2(p);
print2(p);
}
int main(int argc, char const *argv[])
{
test2();
return 0;
}