Skip to content
iamnoobs

Beginner to advanced · 12 modules · 36 lessons

Learn C++: Beginner to Advanced

Learn modern C++ from fundamentals to object-oriented design, STL, resource management, templates, files, testing, and concurrency through short lessons, guided code, quests, and a capstone.

Who this is for: Learners who want to build reliable C++ programs, understand modern language features, and progress from basic syntax to reusable software design.

Prerequisites: No prior C++ experience is needed. Examples target C++17 and are explanatory; they are not compiled or executed on this website.

Meet C++ and the compiler

Source code and main()

A C++ program starts from main() in a hosted application.

C++ source files are commonly saved with a .cpp extension. A compiler translates the source into an executable, and the operating system starts a hosted program by calling main().

The iostream header provides the standard console streams std::cout and std::cin. Names from the standard library live in the std namespace; writing std:: makes their origin explicit.

Guided example

Read through this example; code examples are for learning and are not executed on this site.

#include <iostream>

int main() {
    std::cout << "Hello, C++!\n";
    return 0;
}

Relevance quest · +10 XP

Which function is the usual entry point of a hosted C++ program?

Choose your answer

Mark this lesson complete when you are ready.

Module checkpoint: Meet C++ and the compiler

Try it: create a program that asks for a name and a whole number, validates the numeric input, and prints a personalized message.

After this module, you can:

  • Recognize the role of main() and header files.
  • Compile a source file and distinguish compiler errors from runtime behavior.
  • Use standard input and output for simple programs.

Full curriculum

What you will learn

1. Meet C++ and the compiler

Beginner

Learn how a C++ program is structured, compiled, and run, then begin using standard console input and output.

  1. Source code and main()

    A C++ program starts from main() in a hosted application.

  2. Compile, run, and read diagnostics

    Compilation turns source code into a program and reports many mistakes before execution.

  3. Console input and output

    The standard streams provide a convenient way to read and display values.

Module checkpoint: Try it: create a program that asks for a name and a whole number, validates the numeric input, and prints a personalized message.

2. Types, variables, and expressions

Beginner

Represent data with appropriate types, initialize variables deliberately, and understand operators and conversions.

  1. Variables and initialization

    A variable names an object whose type determines the values and operations it supports.

  2. const and type conversions

    Const-qualified objects cannot be modified through their declared name, and conversions can change representation or value.

  3. Operators and expressions

    Operators combine values to produce new values or comparisons.

Module checkpoint: Try it: calculate a bill total, tax, and per-person split. Decide where integer and floating-point types are appropriate and state any rounding rule.

3. Decisions and loops

Beginner

Control which code runs and repeat operations with conditions that have clear bounds and exit paths.

  1. Conditions and branches

    if and else choose which block executes based on a Boolean condition.

  2. Count with for and range-based for

    A for loop is useful when iteration has a clear initialization, condition, and update.

  3. while, break, and continue

    while repeats while a condition remains true; break and continue alter loop flow.

Module checkpoint: Try it: write a menu-driven program that repeats until the user selects Exit. Test invalid menu choices and the first and last loop iterations.

4. Functions, parameters, and scope

Beginner

Organize programs into reusable functions, pass information safely, and understand overloads and variable scope.

  1. Function declarations and definitions

    A function names a reusable operation with a return type and parameter list.

  2. Pass by value and by reference

    Parameter choice controls whether a function receives a copy or access to an existing object.

  3. Overloading, defaults, and scope

    C++ allows functions to share a name when their parameter lists distinguish them.

Module checkpoint: Try it: design functions to validate a score, calculate an average, and format a summary. Document each function's inputs, outputs, and any side effects.

5. Arrays, strings, and sequences

Beginner

Represent collections and text using standard C++ types that make ownership and size easier to manage.

  1. Fixed-size arrays with std::array

    std::array stores a fixed number of elements and knows its size.

  2. Text with std::string

    std::string manages a sequence of characters and provides common text operations.

  3. Resizable sequences with std::vector

    std::vector is the usual default for a sequence whose size may change at runtime.

Module checkpoint: Try it: read several numbers into a vector, compute the minimum, maximum, and average, and handle the case where no numbers were entered.

6. Classes and object-oriented programming

Intermediate

Bundle state with behavior, enforce class invariants, and use inheritance and polymorphism when they clarify a design.

  1. Classes and encapsulation

    A class defines a type and controls how its state can be accessed.

  2. Constructors and const member functions

    Constructors establish an object's initial valid state.

  3. Inheritance and virtual functions

    Inheritance models an is-a relationship, while virtual functions enable runtime dispatch through a base interface.

Module checkpoint: Try it: implement a BankAccount class with a constructor, a balance query, deposit and withdraw operations, and validation that prevents invalid balances.

7. Pointers, lifetime, and resource management

Intermediate

Understand object lifetime and use modern C++ ownership patterns to avoid leaks, dangling pointers, and double deletion.

  1. Pointers and references

    Pointers represent addresses, while references provide another name for an existing object.

  2. Object lifetime and RAII

    RAII ties a resource's lifetime to an object's lifetime so cleanup happens automatically.

  3. unique_ptr and shared_ptr

    Smart pointers express ownership and automate deletion of dynamically allocated objects.

Module checkpoint: Try it: review a small program with new and delete, then refactor ownership to standard containers or smart pointers. Explain who owns every resource and how long it lives.

8. The standard library: containers and algorithms

Intermediate

Use associative containers, iterators, algorithms, and lambdas to express common data-processing tasks clearly.

  1. Maps, sets, and container choice

    Associative containers organize values by keys or uniqueness rules.

  2. Iterators and traversal

    Iterators provide a common way to refer to elements in many standard containers.

  3. Algorithms and lambda expressions

    Standard algorithms and lambdas let you describe what should happen without writing every loop yourself.

Module checkpoint: Try it: build a word-frequency counter using a map, then display the most useful summaries and explain why you chose that container.

9. Exceptions, validation, and file handling

Intermediate

Handle invalid input and operational failures explicitly, and read or write files using standard C++ streams.

  1. Exceptions and error paths

    Exceptions report failures that prevent an operation from completing normally.

  2. Read and write files

    File streams connect C++ input and output operations to files.

  3. Validate and parse external input

    External input should be checked before it is trusted by the rest of a program.

Module checkpoint: Try it: implement a program that loads records from a text file, detects missing or malformed data, and reports a useful error instead of silently using invalid values.

10. Templates and modern C++ features

Advanced

Write reusable generic code and use modern language features that improve safety, clarity, and performance.

  1. Function and class templates

    Templates let the compiler generate code for types that satisfy the operations the template uses.

  2. Copying, moving, and value categories

    Move operations can transfer resources from temporary or expiring objects instead of duplicating them.

  3. optional, variant, and structured bindings

    Modern library utilities make absence and alternative types explicit in program interfaces.

Module checkpoint: Try it: write a reusable template for finding the maximum value in a compatible sequence, then use std::optional to represent a search that may find nothing.

11. Project structure, testing, and debugging

Advanced

Organize multi-file programs, build with useful diagnostics, and test correctness including boundary and failure cases.

  1. Headers, source files, and namespaces

    A well-organized C++ project separates public interfaces from implementation details.

  2. Build commands and compiler warnings

    A repeatable build command helps catch issues consistently across a project.

  3. Testing and debugging systematically

    Focused tests and deliberate debugging make failures easier to reproduce and fix.

Module checkpoint: Try it: split a small program into a header, implementation file, and main file. Add tests for normal and boundary behavior, then compile with warnings enabled.

12. Concurrency fundamentals

Advanced

Understand basic multithreading tools and shared-state risks, and learn when concurrency adds complexity rather than value.

  1. Starting and joining threads

    A thread allows a program to execute work concurrently with other threads.

  2. Mutexes and shared data

    A mutex can ensure only one thread at a time accesses a protected critical section.

  3. Tasks, futures, and concurrency design

    Higher-level task tools can make results and synchronization more explicit.

Module checkpoint: Try it: create two independent computations, collect their results, and explain why the work is safe to run concurrently. Then identify what synchronization would be required if they shared mutable state.

Put it together

C++ capstone: Personal expense tracker

Build a command-line expense tracker that records expense descriptions, categories, dates, and amounts. Use classes to model records, standard containers to manage them, algorithms to summarize spending, and file streams to save and reload data. Validate every input and handle file errors explicitly.

  1. 1Define an Expense class or struct with a clear representation for description, category, date, and amount; validate the values at the program boundary.
  2. 2Create a menu for adding, listing, searching, and removing expenses, with each operation implemented as a focused function.
  3. 3Store records in a std::vector and use standard algorithms or loops to calculate totals by category and date range.
  4. 4Read and write records using file streams, checking open and operation states and defining how malformed records are handled.
  5. 5Add a summary report, tests for empty and invalid inputs, file-error cases, and boundary amounts; compile with warnings and document the build steps.

Progress is saved in this browser when local storage is available. You can continue without an account; changing browsers or clearing browser data may remove saved progress. Examples are not executed by the site.