-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex9_13.cpp
45 lines (41 loc) · 893 Bytes
/
ex9_13.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
//! @author @shbling @Alan
//!
//! Exercise 9.13:
//! How would you initialize a vector<double> from a list<int>?
//! From a vector<int>?
//! Write code to check your answers.
//!
#include <iostream>
#include <list>
#include <string>
#include <vector>
using std::cout;
using std::endl;
using std::list;
using std::vector;
int main()
{
list<int> ilst(5, 4);
vector<int> ivc(5, 5);
//! from list<int> to vector<double>
vector<double> dvc(ilst.begin(), ilst.end());
for (auto i : ilst) {
cout << i << " ";
}
cout << endl;
for (auto t : dvc) {
cout << t << " ";
}
cout << endl;
//! from vector<int> to vector<double>
vector<double> dvc2(ivc.begin(), ivc.end());
for (auto i : ivc) {
cout << i << " ";
}
cout << endl;
for (auto t : dvc2) {
cout << t << " ";
}
cout << endl;
return 0;
}