C++ Tutorial
Powerful, fast code for games, systems and performance.
Getting started4 lessons
Basics21 lessons
- 5Variables and Typesint, double, char, bool and string.
- 6User Inputcin and getline.
- 7OperatorsArithmetic, comparison and logic.
- 8StringsThe string class.
- 9Math Functionscmath helpers.
- 10C++ Data TypesBasic types: int, long, short, float, double, char, bool and std::string.
- 11Constants and Castsconst and constexpr declare constants, constexpr at compile time.
- 12Enums and Structsenum class defines scoped, type safe constants.
- 13C++ String Methodsstd::string has size, empty, substr, find, replace, append, insert, erase and comparison.
- 14Input and Output Streamscout prints and cin reads.
- 15Math and Random Numbers<cmath> has sqrt, pow, abs, floor, ceil and round.
- 16Variables and TypesC++ is statically typed.
- 17cout and cincout prints with << and cin reads with >>.
- 18std::stringstd::string grows automatically.
- 19Reading Linesgetline reads a whole line.
- 20const and constexprconst values cannot change.
- 21CastingUse static_cast for safe conversions.
- 22ReferencesA reference is another name for a variable.
- 23PointersA pointer stores an address.
- 24NamespacesNamespaces group names and avoid clashes.
- 25OperatorsArithmetic, comparison, logical and bitwise operators.
Control flow11 lessons
- 26If and SwitchDecisions.
- 27Loopswhile, do...while, for and range-based for.
- 28switch, Ternary and Range Forswitch matches integers and enums, the ternary operator is a short if, and a range based f.
- 29while, do while and breakwhile checks before, do while checks after.
- 30Structured Bindings and if initStructured bindings unpack pairs, tuples and structs into variables.
- 31if, else if and elseBranch with conditions.
- 32switchswitch compares an integral value with cases.
- 33Loopsfor, while and do while repeat code.
- 34Range based forfor (auto x : c) copies, for (auto& x : c) modifies and for (const auto& x : c) reads with.
- 35break and continuebreak leaves a loop and continue skips a round.
- 36Structured BindingsUnpack pairs, tuples and structs into named variables.
Functions14 lessons
- 37FunctionsReusable blocks of code.
- 38Lambdas and RecursionSmall functions and self calls.
- 39Reference and Default ParametersPass by reference (&) to avoid copies and to change the caller variable.
- 40Function TemplatesA template writes one function for many types.
- 41inline, constexpr and noexcept Functionsconstexpr functions can run at compile time.
- 42std::function and Callbacksstd::function stores any callable: functions, lambdas and functors.
- 43FunctionsA function has a return type, name and parameters.
- 44Default ArgumentsGive parameters default values.
- 45Function OverloadingSame name with different parameter types.
- 46Pass by Value, Reference and const ReferencePass by value copies.
- 47LambdasA lambda is an inline function.
- 48std::functionstd::function stores any callable and is handy for callbacks.
- 49Function TemplatesTemplates write one function for many types.
- 50RecursionA function may call itself with a base case.
Data structures22 lessons
- 51Arrays and VectorsFixed and growing lists.
- 52Maps and SetsKey and value pairs and unique values.
- 53Pointers and ReferencesAddresses and aliases.
- 54Dynamic Memory and Smart Pointersnew, delete and unique_ptr.
- 55Vector In Depthvector grows automatically.
- 56array, deque and liststd::array is a fixed size array with a size, deque is a double ended queue and list is a .
- 57map, unordered_map and multimapmap keeps keys sorted, unordered_map uses hashing and is usually faster, and multimap allo.
- 58set, stack, queue and priority_queueset keeps unique sorted values, stack is last in first out, queue first in first out, and .
- 59pair, tuple, optional and variantpair and tuple group values, optional holds a value or nothing and variant holds one of se.
- 60string_view and Iteratorsstring_view is a cheap read only view of text without copying.
- 61std::array and C Arraysstd::array has a fixed size and safe helpers.
- 62std::vectorvector is a resizable array.
- 632D VectorsA vector of vectors makes a grid.
- 64std::mapmap stores sorted key value pairs.
- 65unordered_map and unordered_setHash based containers give fast average lookup but no order.
- 66std::setset keeps unique values sorted.
- 67stack and queuestack is last in first out and queue is first in first out.
- 68pair and tuplepair holds two values and tuple holds many.
- 69Algorithms<algorithm> has sort, find, count, reverse, min_element, max_element, accumulate and more.
- 70Custom SortingPass a comparator or lambda to sort.
- 71IteratorsIterators point at elements.
- 72optional and variantoptional holds a value or nothing.
Object oriented programming19 lessons
- 73Classes and ObjectsBundling data and behaviour.
- 74Inheritance and PolymorphismExtending classes.
- 75Operator Overloading and TemplatesCustom operators and generic code.
- 76Constructors, Destructors and RAIIConstructors set up an object and destructors clean up.
- 77Access Control, const and friendpublic, protected and private control access.
- 78static Members and thisstatic members belong to the class, shared by all objects.
- 79Copy and Move SemanticsThe copy constructor duplicates an object, while move steals resources from a temporary, w.
- 80Virtual Functions and Abstract Classesvirtual functions are resolved at runtime.
- 81Multiple Inheritance and InterfacesA class can inherit from several bases.
- 82ClassesA class has data and member functions.
- 83Constructors and DestructorsThe constructor sets up an object and the destructor cleans up when it ends.
- 84InheritanceA derived class inherits from a base.
- 85Abstract ClassesA pure virtual function (= 0) makes a class abstract.
- 86Operator OverloadingDefine + and << for your types to make them natural to use.
- 87static Membersstatic members belong to the class and are shared by all objects.
- 88structstruct is a class with public default access.
- 89enum classScoped enums avoid name clashes and do not convert to int by accident.
- 90Smart Pointersunique_ptr owns one object, shared_ptr shares ownership.
- 91Move Semanticsstd::move turns a value into an rvalue so its resources can be moved instead of copied.
Standard library and files15 lessons
- 92Algorithms and Iteratorssort, find, count and more.
- 93Exceptionstry, catch and throw.
- 94Filesifstream and ofstream.
- 95More STL Algorithms<algorithm> offers sort, find, count_if, transform, accumulate, remove_if, unique, reverse.
- 96File Streamsofstream writes and ifstream reads files.
- 97chrono and filesystem<chrono> measures time and <filesystem> works with paths and directories (C++17).
- 98Regular Expressions and Text<regex> matches patterns with regex_match, regex_search and regex_replace.
- 99Exceptionsthrow an exception and catch it with try catch.
- 100File Streamsofstream writes and ifstream reads files.
- 101stringstreamstringstream builds and parses text like a file.
- 102chrono and random<random> makes good random numbers and <chrono> measures time.
- 103string_viewstring_view looks at text without copying it.
- 104Practice: Word FrequencyUse a map to count words.
- 105Practice: PalindromeCompare a string with its reverse.
- 106Practice: Top ScoresSort a vector of pairs and print the top two.
Advanced C++Premium8 lessons
- 107Smart Pointersunique_ptr owns an object exclusively, shared_ptr shares ownership with reference counting.
- 108Class TemplatesClasses can be templates too, such as a generic Stack.
- 109Concepts and Constraints (C++20)Concepts name requirements on template parameters, giving clear error messages.
- 110Lambdas In DepthLambdas capture by value [x], by reference [&x], everything [=] or [&], and can be mutable.
- 111Rvalue References and Perfect ForwardingT&& binds to temporaries, enabling moves.
- 112Threads, Mutexes and Atomicsstd::thread runs functions concurrently, mutex and lock_guard protect shared data and atom.
- 113async, future and promisestd::async runs a task possibly on another thread and returns a future.
- 114Exceptions and Exception SafetyThrow by value, catch by const reference and derive from std::exception.
C++ in practicePremium7 lessons
- 115CMake and Build SystemsCMake generates build files from CMakeLists.txt.
- 116Testing with GoogleTest and Catch2Unit test frameworks such as GoogleTest and Catch2 provide test cases and assertions.
- 117Debugging and SanitizersUse gdb or lldb for stepping, -fsanitize=address,undefined for runtime checks, valgrind fo.
- 118Performance and OptimisationCompile with -O2, measure before tuning, prefer vectors to lists, reserve capacity, avoid .
- 119Libraries, Modules and PackagesPackage managers such as vcpkg and Conan fetch libraries like Boost, fmt and nlohmann json.
- 120Where C++ Is UsedC++ powers game engines such as Unreal, browsers, databases, finance systems, embedded dev.
- 121C++ Best PracticesFollow the C++ Core Guidelines: use RAII, smart pointers, const, auto where clear, range f.