-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.cpp
More file actions
28 lines (28 loc) · 960 Bytes
/
vector.cpp
File metadata and controls
28 lines (28 loc) · 960 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
#include<iostream>
#include<vector> //STL: Standard template library
using namespace std;
int main(){
vector<int> vec;
cout<<vec.size()<<endl; //Output: 0
vec.push_back(5);
cout<<vec.size()<<endl; //Output: 1
vec.pop_back();
cout<<vec.size()<<endl; //Output: 0
vector<int> vect={1,2,33};
cout<<vect[1]<<endl; //Output: 2
cout<<vect.size()<<endl; //Output:3
cout<<vect.front()<<" "<<vect.back()<<endl; //Output: 1 33
vector<int> vec2(4,8);
cout<<vec2[3]<<endl; //Output: 8
for (int i: vec2){
cout<<i<<" "; //Output: 8 8 8 8
}
cout<<endl;
vector<char> charVec={'a','b','c'};
for(char i: charVec){
cout<<i<<" "; //Output: a b c
}
cout<<endl;
cout<<charVec.at(0)<<endl; //Output: a
return 0;
}