Default value

Arrays and collections / Dictionaries

#include <iostream>
#include <map>
using namespace std;

map<int, string>  d = {
    {1, "A"}, {2, "B"}
};

//since C++17
auto value3 = d.try_emplace(3, "-");
//(*value3.first).second is "-"

bool exist3 = d.contains(3);
//exist3 is 1

cout << "exist3 is " << exist3 << endl;
cout << "value3 is '" << (*value3.first).second << "'"