forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex12_06.cpp
47 lines (40 loc) · 1.14 KB
/
ex12_06.cpp
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
/***************************************************************************
* @file The code is for the exercises in C++ Primmer 5th Edition
* @author Yue Wang
* @date 22 DEC 2013
* Jun 2015
* Oct 2015
* @remark
***************************************************************************/
//
// Exercise 12.6:
// Write a function that returns a dynamically allocated vector of ints.
// Pass that vector to another function that reads the standard input to
// give values to the elements. Pass the vector to another function to print
// the values that were read.
// Remember to delete the vector at the appropriate time.
//
#include <iostream>
#include <vector>
using Ptr = std::vector<int>*;
auto make_dynamically()
{
return new std::vector < int > { };
}
auto populate(Ptr vec)
{
for (int i; std::cout << "Pls Enter:\n", std::cin >> i; vec->push_back(i));
return vec;
}
auto print(Ptr vec) -> std::ostream&
{
for (auto i : *vec) std::cout << i << " ";
return std::cout;
}
int main()
{
auto vec = populate(make_dynamically());
print(vec) << std::endl;
delete vec;
return 0;
}