I want to assign a vector as value to keys in unorderd_map.
int main()
{
std::unordered_map<int,std::vector<int>> a1;
std::vector<int> t1 = {10};
a1[1]=t1; //question
a1[1].push_back(11);
a1[1].push_back(12);
// ....
// ....
}
In my case, I first want to assign t1 to a key and then add values to the vector a1[1]. Instead of defining t1, how can I assign a vector on the fly? Something like a1[1] = std::vector<int> {10} ? Do I have to define a temporary variable, t1 in this case?
Aucun commentaire:
Enregistrer un commentaire