forked from Bhupesh-V/30-seconds-of-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
push_back.cpp
41 lines (30 loc) · 972 Bytes
/
push_back.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
// Follow the Style Guide while submitting code PR.
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : Kamal Kant Sharma
Date : 05/07/2019
Time : 13:44
Description : std::vector::push_back from STL is used to add new elements to the end of the vector.
*/
#include <iostream>
#include <vector>
#include<string>
void print(const std::string &vector_name, const std::vector<int> &vec){
//Function to print the vector name and the vector
std::cout << vector_name << "{ ";
for (auto num : vec){
std::cout << num << " ";
}
std::cout << "}" << std::endl;
}
int main (){
//Intializing the vectors
std::vector<int> vector1 ;
print("Vector 1 : ", vector1);
std::cout << "Adding elements using STL vector push_back function" << std::endl;
vector1.push_back(1);
vector1.push_back(2);
vector1.push_back(3);
print("Vector 1 : ", vector1);
return 0;
}