-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstdcopy.cpp
More file actions
39 lines (31 loc) · 718 Bytes
/
stdcopy.cpp
File metadata and controls
39 lines (31 loc) · 718 Bytes
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
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;
int main(int argc, char **argv)
{
list<int> l;
vector<int> v;
int randValue;
// create a vector with 10 random elements
for (int i=0; i < 10; i++) {
randValue = rand() % 100;
v.push_back(randValue);
}
// print the list of vectors
vector<int>::const_iterator pos;
for (pos = v.begin(); pos != v.end(); ++pos) {
cout << *pos << " ";
}
l.resize(v.size());
std::copy(v.begin(), v.end(), l.begin());
// print the list of vectors
cout << endl;
list<int>::const_iterator li;
for (li = l.begin(); li != l.end(); ++li) {
cout << *li << " ";
}
cout << endl;
return 0;
}