-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInitialization.cpp
More file actions
88 lines (66 loc) · 1.54 KB
/
Initialization.cpp
File metadata and controls
88 lines (66 loc) · 1.54 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* \file Initialization.cpp
* \brief
*
* \todo
*/
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <iterator>
using namespace std;
void example1()
{
std::vector<int> vectorOfInt(5);
for (int x : vectorOfInt)
cout << x << endl;
}
void example2()
{
std::vector<string> vectorOfString(5, "Hi");
for (string x : vectorOfString)
cout << x << endl;
}
void example3()
{
string arr[] = {"First", "Second", "Third", "Fourth"};
std::vector<string> vectorOfString(arr, arr + sizeof(arr)/sizeof(string));
for (string x : vectorOfString)
cout << x << endl;
}
void example4()
{
list<string> listOfStr;
listOfStr.push_back("first");
listOfStr.push_back("second");
listOfStr.push_back("third");
listOfStr.push_back("fourth");
std::vector<string> vectorOfString(listOfStr.begin(), listOfStr.end());
for (string x : vectorOfString)
cout << x << endl;
}
void example5()
{
std::vector<string> vectorOfString;
vectorOfString.push_back("first");
vectorOfString.push_back("second");
vectorOfString.push_back("third");
vector<string> vectorCopy(vectorOfString);
for (string x : vectorCopy)
cout << x << endl;
}
int main()
{
cout << "Vector Initialization with Default Values" << endl;
example1();
cout << "Vector Initialization with similar copy of elements" << endl;
example2();
cout << "Vector Initialization with an array" << endl;
example3();
cout << "Vector Initialization with a list" << endl;
example4();
cout << "Vector initialization with another vector" << endl;
example5();
return 0;
}