What's Next
You started with one line of cout. Here is what you can use now:
- Basics: variables, data types, constants, input, operators, math functions and integer limits
- Control flow:
if,switch, the ternary operator, andfor,whileanddo-whileloops - Functions: parameters, return values, references, scope, overloading and recursion
- Arrays and strings: arrays, 2D arrays, strings, characters and string functions
- Vectors: adding, inserting and removing values, vectors in functions, 2D vectors
- Pointers and memory: pointers, and heap memory with
newanddelete - Classes: enums, structs, constructors, encapsulation, static members, operator overloading, inheritance, polymorphism, abstract classes and smart pointers
- Templates: your own function templates and class templates
- The standard library: pairs, maps, sets, unordered maps, stacks, queues, priority queues, iterators, algorithms, lambdas and exceptions
That is the core of modern C++.
Picking a container
Choosing where to keep the data is one of the first decisions in most programs. This table sums up the containers from the course:
| You need | Use |
|---|---|
| values in order, found by index | vector |
| a value for each key, keys sorted | map |
| a value for each key, fast, no order | unordered_map |
| each value only once | set or unordered_set |
| the last value added comes out first | stack |
| the first value added comes out first | queue |
| the largest value always comes out first | priority_queue |
When you are not sure, start with a vector.
What to learn next
- Move semantics. When a function returns a big vector, C++ can move the data to the caller instead of copying it. You used
movewith smart pointers. Next, learn what it really does and when it makes a program faster. - Programs in many files. Real programs split their code into header files (
.h) and source files (.cpp). A build tool compiles them together. - A real project. Build a small game or a tool that is too big for one file. You will use almost everything from this course.
- Practice problems. Coding interview problems use the tools from this course again and again: vectors, maps, sets, stacks, queues,
sortandbinary_search. Solve a few every week.
The best habit from this course is simple: run the code, look at what really happened, and learn from the surprises.
The last question asks you to pick the right container for a job. Then you have finished the course. Well done!