In std::vector there a fucntion call push_back is there something equivalent to that in std::map
insert
(which will fail if the key already exists in the map). Since a map is sorted, adding something "to the end" doesn't make any sense.
Last edited on
thank you i thought it was insert but wasnt sure
std::map also offers an overload of operator [] for insertion:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
# include <iostream>
# include <string>
# include <map>
int main()
{
std::map<std::string, double> studentScores{};
studentScores["John Smith"] = 71;
studentScores["Jane Doe"] = 89;
for (const auto& elem : studentScores)
{
std::cout << elem.first << " " << elem.second << "\n";
}
}
|
Last edited on