samedi 27 mars 2021

2D Vectors push_back

I'm trying to push_back numbers into a 2D vector that's composed of 1 row and 1 column.

    vector< vector <int>>array;
    array.push_back(vector<int>(3)); 
    array[0].push_back(2);
    cout << array[0][0] << endl;

I expected this to return 3, but it returns 0. Why's that?

Aucun commentaire:

Enregistrer un commentaire