-
Notifications
You must be signed in to change notification settings - Fork 33
/
12.06.cpp
43 lines (38 loc) · 844 Bytes
/
12.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
/*
* 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.
*
* By Faisal Saadatmand
*/
#include <iostream>
#include <string>
#include <vector>
#include <memory>
std::vector<int> *allocVector()
{
return new std::vector<int>();
}
void fillVector(std::istream &is, std::vector<int> *pv)
{
int i;
while (is >> i)
pv->push_back(i);
}
void printVector(std::ostream &os, std::vector<int> *pv)
{
for (auto &elem : *pv)
os << elem << ' ';
}
int main()
{
auto *p = allocVector();
fillVector(std::cin, p);
printVector(std::cout, p);
std::cout << std::endl;
delete p;
p = nullptr;
std::cout << p << '\n';
return 0;
}