liveBook · Manning

At

As explained in Learn C++ by Example

at is a map member function that accesses the value for a key without inserting a missing entry and throws std::out_of_range if the key is absent.

std::map::at accesses the value associated with an existing key without inserting anything. Unlike operator[], it can be called on a const map; a missing key throws std::out_of_range. section 7.1.1 section 7.4

Querying a dictionary safely

Given a map named lookup, write `auto value = lookup.at("cheese");`. This reads the existing value while preserving the map. By contrast, `lookup["cheese"]` may insert an empty string when the key is absent. section 7.1.1

auto value = lookup.at("cheese");

Use the compact listing to compare the const-safe at call with the non-const operator[] alternative. section 7.1.1

How Learn C++ by Example covers it

How deep it goes
Explains const access, accidental insertion, and std::out_of_range, but does not develop exception handling.
Examples
Demonstrates dictionary lookups for fictional and cheese keys, contrasting at with operator[].
What it assumes
Assumes familiarity with std::map and operator[], while clarifying const member access from practical examples.
What you can do after
Apply it via std::map to perform non-inserting lookups and recognize missing-key exceptions.
How it connects
Connects std::map::at with operator[], const references, and std::out_of_range exceptions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn C++ by Example. The section links point to the parts of the book it draws on.