C++ STL Cheatsheet
Quick reference for STL containers, algorithms, iterators, string utils, and helpers.
| Item | Description | Example | Category |
|---|---|---|---|
| vector | Dynamic array | vector<int> v = {1,2,3}; | Containers |
| array | Fixed-size array | array<int, 5> arr = {1,2,3,4,5}; | Containers |
| deque | Double-ended queue | deque<int> dq; | Containers |
| list | Doubly linked list | list<int> li; | Containers |
| stack | LIFO container | stack<int> st; | Containers |
| queue | FIFO container | queue<int> q; | Containers |
| priority_queue | Max heap (default) | priority_queue<int> pq; | Containers |
| set | Sorted unique elements | set<int> s; | Containers |
| unordered_set | Hash table set | unordered_set<int> us; | Containers |
| map | Key-value sorted | map<int,string> mp; | Containers |
| unordered_map | Key-value hash | unordered_map<int,string> ump; | Containers |
| begin(), end() | Start & end iterator | for(auto it=v.begin(); it!=v.end(); it++) | Iterators |
| rbegin(), rend() | Reverse iterators | for(auto it=v.rbegin(); it!=v.rend(); it++) | Iterators |
| sort() | Sort ascending | sort(v.begin(), v.end()); | Algorithms |
| reverse() | Reverse range | reverse(v.begin(), v.end()); | Algorithms |
| max_element() | Find max element | auto x = max_element(v.begin(), v.end()); | Algorithms |
| min_element() | Find min element | auto x = min_element(v.begin(), v.end()); | Algorithms |
| count() | Count occurrences | count(v.begin(), v.end(), 3); | Algorithms |
| binary_search() | Check existence | binary_search(v.begin(), v.end(), 5); | Algorithms |
| lower_bound() | 1st ≥ element | lower_bound(v.begin(), v.end(), 5); | Algorithms |
| upper_bound() | 1st > element | upper_bound(v.begin(), v.end(), 5); | Algorithms |
| accumulate() | Sum range | accumulate(v.begin(), v.end(), 0); | Algorithms |
| pair | Store 2 values | pair<int,string> p = {1,"a"}; | Utility |
| make_pair() | Create pair | auto p = make_pair(1,"a"); | Utility |
| tuple | Store multiple values | tuple<int,string,double> | Utility |
| tie() | Unpack tuple | tie(a,b)=p; | Utility |
| swap() | Swap values | swap(a,b); | Utility |
| string | Dynamic string | string s = "hello"; | Strings |
| stoi() | String → int | int x = stoi("123"); | Strings |
| to_string() | To string | string s = to_string(10); | Strings |
| sizeof() | Size in bytes | sizeof(x) | Others |
| iota() | Fill increasing sequence | iota(v.begin(), v.end(), 1); | Others |