Skip to content

Commit 7b325e1

Browse files
committed
Standard Template Library in C++ learn with simple examples
1 parent 73f570d commit 7b325e1

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

STL.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//* STL-> Standard Template Library
2+
#include<iostream>
3+
#include<vector>
4+
5+
using namespace std;
6+
7+
// template<class T>
8+
void display(vector<int> &v){
9+
for (int i = 0; i < v.size(); i++){
10+
cout << v[i] << " ";
11+
cout << "i'm at "<<v.at(i) <<endl;
12+
}
13+
cout << endl;
14+
}
15+
16+
int main(){
17+
vector<int> vec;
18+
int element, size;
19+
cout << "Enter the size of vector: " << endl;
20+
cin >> size;
21+
for (int i = 0; i < size; i++){
22+
cout << "Enter an element value to add in vector: ";
23+
cin >> element;
24+
vec.push_back(element);
25+
}
26+
// vec.pop_back(); // delete last element
27+
display(vec);
28+
29+
// vector<int>::iterator iter = vec.begin();
30+
// vec.insert(iter, 7); // iter -> postion index 0, iter+1 -> position index 1... // if you want to 7 print 10 times then use (iter, 10, 7)
31+
// display(vec);
32+
//? Vector methods
33+
return 0;
34+
}

STL.exe

64.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)