samedi 25 septembre 2021

How to push back a vector into a map

What I want to do here is to create a map like this:

0 -> 0,1,...,4;
1-> 0,1,...,4;
...
9 -> 0,1,...,4;
int main(){
    map<int, vector<int>> m;
    for(int i=0; i<10; i++){
        vector<int> temp;
        for(int j=0; j<5; i++){
            temp.push_back(j);
        }
        m.insert({i, m.push_back(temp)});
    }
}

But when I try to push back temp = {0,1,2,3,4} vector, it's giving me an error.

I guess there is some problem in the syntax of the underlined line.

Can you tell me how to solve this error?

Screenshot of the code

Aucun commentaire:

Enregistrer un commentaire