Standard Template Library (STL)
Containers
Common STL containers and their usage.
1
2
3
4
5
6
7
8
9
10
11
12
// Vector - Dynamic Array
vector<int> vec = {1, 2, 3};
vec.push_back(4);
// List - Doubly Linked List
list<string> lst = {"apple", "banana"};
lst.push_front("orange");
// Map - Key-Value Pairs
map<string, int> ages;
ages["Alice"] = 25;
ages["Bob"] = 30;
CPP UTF-8
Lines: 12
Algorithms
Essential STL algorithms.
1
2
3
4
5
6
7
8
9
10
11
vector<int> nums = {3, 1, 4, 1, 5, 9};
// Sorting
sort(nums.begin(), nums.end());
// Finding elements
auto it = find(nums.begin(), nums.end(), 4);
// Counting elements
int count = count_if(nums.begin(), nums.end(),
[](int n) { return n > 3; });
CPP UTF-8
Lines: 11