C++ 23 · Language basics

Declare a variable in an if

Limit a variable's scope to the if and else branches.

if (auto it = scores.find("Ada"); it != scores.end()) {
    std::cout << it->second << '\n';
}

Official C++ 23 documentation

More language basics commands

All language basics commands · C++ 23 cheatsheet

Was this page helpful?