Programming foundations

Stage 1 · Lesson 5 of 8

std::vector, std::string and std::map

Your first language

The gives you safe containers that grow as needed, so you rarely need raw . A std::vector<int> grows with push_back and reports its length with size(). v[i] does no , so a wrong index silently reads memory it should not.

v.at(i) throws an error if i is out of range, which is useful while learning. std::string handles text with +, size(), substr() and find(), and compares with ==, unlike old C . A std::map<std::string, int> stores pairs with the keys kept in sorted order.

std::unordered_map is usually faster when you do not need order. Beware that counts["bob"] inserts a zero entry when the key is missing. Use find() or, from C++20, contains() to check first. These three cover almost everything the milestone needs.

A question to check yourself, an AI practice session and 3 cheat sheet entries come when you add the roadmap to your account. Add it

Resources for this stage

Start with

  • CourseFree
    LearnCpp.com

    LearnCpp.com · Beginner

    Free, current and careful: chapters 0 to 16 take you from setup to references and std::vector

Practise

  • Small exercises in your language track, with free feedback from a human mentor

Keep handy

  • The standard library reference: check std::vector and std::string pages as you use them

  • Quick syntax lookups and an online compiler for testing a snippet on a shared computer

Mark this stage as not done?