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
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector <int *> v1;
vector <int> v2;
vector <int> *v3;
int i;
int *p;
v3 = &v2;
while (cin >> i) {
p = new int;
*p = i;
v1.push_back(p);
v2.push_back(*p);
}
for (i = 0; i < v1.size(); i++) *(v1[i]) += 2;
for (i = 0; i < v2.size(); i++) v2[i] += 10;
for (i = 0; i < v1.size(); i++) cout << *(v1[i]) << endl;
for (i = 0; i < v2.size(); i++) cout << v2[i] << endl;
for (i = 0; i < v3->size(); i++) cout << v3->at(i) << endl;
return 0;
}
Behold the program to the right. We compile it to the file a.out and then we run it with:
UNIX> echo 30 50 70 | ./a.out
32
52
72
40
60
80
40
60
80
No Class Stats, PDF Download