The standard library (STL)
Containers and algorithms remove whole classes of hand-written loops.
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.
#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
MediumSort and search
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 inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.