C++ Cheatsheet
Vector
Matrix
String
std::string
’s methods are a superset of the std::vector
’s methods. These are some specific methods to know:
Map
For unordered maps:
Initialising a map
Initialising a static member of a class.
Stack, Queue
Set
- On failure to read, they’ll just be uninitialised
When reading formatted input and then unformatted input, you’ll need to call the ignore
method, std::cin.ignore()
, in between.
Algorithm
Iterators
Missing String Functions
Typecasting & Data Structure Conversion
Tidbits
- Under the hood,
vector::clear
may not actually clear out values from the vector.
- Careful, you’ll get a segfault when the iterator is out of bounds. Eg. v.begin() + 1 in an empty vector.
- The reason this doesn’t return a value is because of exception safety.
- Vector, map and set all share some common method names: insert, erase, clear, size, etc.