noknow.dev
Sign inSign up
Course overview
C++ Fundamentals
0 / 39 lessons0%

Getting Started

  • Hello, World!
  • Variables and Data Types
  • Arithmetic and Operators
  • Working with std::string
  • Type Conversion and Casting

Control Flow

  • if / else if / else
  • switch / case
  • while and do-while Loops
  • for Loops
  • break, continue, and Finding Primes

Functions

  • Writing Functions
  • Pass by Value vs. Pass by Reference
  • Overloading and Default Parameters
  • Recursion

Arrays and Strings

  • C-style Arrays
  • std::vector — Dynamic Arrays
  • std::string Deep Dive
  • 2D Arrays and Matrices

Pointers and Memory

  • Memory Addresses and Pointers
  • Dynamic Memory: new and delete
  • References vs Pointers

Object-Oriented Programming

  • Classes and Objects
  • Constructors and Destructors
  • Inheritance
  • Virtual Functions and Polymorphism
  • Operator Overloading

The Standard Template Library

  • std::vector in Depth
  • std::map and std::unordered_map
  • std::set and Sorted Unique Collections
  • STL Algorithms

Templates and Generic Programming

  • Function Templates
  • Class Templates

Modern C++ (C++11/14/17)

  • auto and Range-based for
  • Lambda Functions
  • Smart Pointers
  • Move Semantics

Error Handling and Exceptions

  • try / catch / throw
  • Custom Exception Classes
  • RAII and Resource Management

std::map and std::unordered_map

0m 00s

Key-Value Stores

map is sorted by key. unordered_map uses hashing (faster, but unsorted):

#include <map>

map<string, int> ages;
ages["Alice"] = 30;
ages["Bob"]   = 25;

cout << ages["Alice"];          // 30
cout << ages.count("Dave");    // 0 (missing keys return 0)
ages.erase("Bob");

for (auto& [name, age] : ages) {  // structured bindings (C++17)
    cout << name << ": " << age;
}

if (ages.find("Alice") != ages.end()) {
    cout << "Found!";
}

Your Task

Write wordCount(string text) returning a map<string,int> with the frequency of each word.
Example: "the cat sat on the mat" → {cat:1, mat:1, on:1, sat:1, the:2}

Back
cppCtrl+Enter to run
Output

Click "Run" to execute your code.