-
Notifications
You must be signed in to change notification settings - Fork 0
/
66.) Tut 71( Vector In C++ STL).cpp
41 lines (38 loc) · 1.19 KB
/
66.) Tut 71( Vector In C++ STL).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
#include<iostream>
#include<vector>
using namespace std;
template <class T>
void display(vector<T> &v){
cout<<"displaying this vector: "<<endl;
for (int i = 0; i < v.size(); i++)
{
cout<<v[i]<<" ";
//cout<<v.at(i)<<" ";
}
cout<<endl;
}
int main(){
//vector<int> vec1;
int element, size =5;
//cout<<"Enter the size of your vector"<<endl;
//cin>>size;
//for (int i = 0; i < size; i++)
//{
// cout<<"Enter an element to add to this vector: ";
// cin>>element;
// vec1.push_back(element);
//}
//vec1.pop_back();
//display(vec1);
//use of iterator and insert
// vector<int> :: iterator iter = vec1.begin();
// vec1.insert(iter+2,5, 566);//iter +2 means 566 is placed after v2 element that we input. iter, 5 means 566 is repatedly coming for 5 times
// display(vec1);
// vector<int> vec1; //zero length integer vector
// vector<char> vec2(4); //4-element character vector
// vector<char> vec3(vec2);//4-element character vector from vec2
vector<int> vec4(4,13); //6-element vector of 3s
display(vec4);
cout<<vec4.size();
return 0;
}