Learn C++
Free C++ guides and exercises
These free C++ guides explain 17 practical topics with complete examples, expected output, and short exercises. Use them when you need a focused explanation of a language feature, runtime problem, or compiler message. Each guide names the cause early and shows how to inspect the code and correct it.
The guides group related material so you can follow a problem from one page to another. Start with containers and loops, then review input and strings when your program reads user data. Runtime guides explain invalid indexing and arithmetic boundaries. Compiler and linker guides help you interpret diagnostics, separate declaration mistakes from build errors, and understand how source files fit together. Every complete program targets C++17 and includes its expected output. Try an exercise after reading, then compare your approach with its optional solution. The pages provide a reference for your own programs and do not require an account to read.
Containers and loops
- C++ std::vector for beginners - Store and access a changing sequence of values.
- C++ loops practice - Choose a loop and control its execution.
Input and strings
- Validate user input in C++ - Detect failed input and recover the stream.
- Why std::getline skips input after std::cin - Handle the newline left by formatted input.
Runtime errors and undefined behavior
- C++ integer overflow - Check whether arithmetic fits its type.
- C++ vector subscript out of range - Check bounds before indexing.
- C++ terminate called after throwing - Handle exceptions before they terminate the program.
Compiler and linker errors
- C++ undefined reference errors - Diagnose missing definitions at link time.
- C++ was not declared in this scope - Check visibility, headers, and declaration order.
- C++ no matching function for call - Compare arguments with candidate signatures.
- C++ multiple definition linker error - Define shared functions and globals once.
- C++ expected semicolon before - Find the missing terminator near the diagnostic.
- C++ expected primary-expression before - Correct a missing or misplaced expression.
- C++ does not name a type - Check headers, scope, and type declaration order.
- C++ invalid conversion from const char* to char - Match character and string types.
Compiler warnings
- C++ control reaches end of non-void function - Return a value along every valid path.
- C++ signed and unsigned comparison warning - Compare compatible types in loops.