C++ Foundations·Modern C++ without the folklore

The standard library (STL)

Containers and algorithms remove whole classes of hand-written loops.

Intermediate 15 min read Lesson 8 of 300 Challenge included
What you will be able to do
  • Prefer vector for contiguous storage and iteration.
  • Use unordered_map for average constant-time key lookup.
  • Use std::sort with a clear comparator.

In plain English

vector is the default sequence; map and unordered_map provide lookup. Algorithms such as sort, find_if and accumulate express intent. Choose a container by its access pattern, not by habit.

stl.cppC++
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

int main() {
    std::vector<std::string> lessons = {"HTML", "CSS", "Git"};
    std::sort(lessons.begin(), lessons.end());

    for (const auto& lesson : lessons) {
        std::cout << lesson << "\n";
    }

    auto it = std::find(lessons.begin(), lessons.end(), "CSS");
    std::cout << (it != lessons.end() ? "found" : "missing") << "\n";
}
Your turn

Sort and search

Medium

Sort a vector of lesson titles and use std::find to check whether "Git" exists.

CPP · starter
std::vector<std::string> lessons = {"HTML", "CSS", "Git"};
Check your understanding before moving on.
Knowledge checkQuestion 1

Which container is usually the best default for a sequence?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Lesson 8 of 300 · 0% of course