mardi 24 novembre 2020

Subscripted value is not an array, pointer, or vector - C++

I am simply trying to reverse the values inside my vector of a vector. This is my first time coding in C++ and am kind of frustrated as to what is going wrong.

Defining the variable:

vector<vector<int>> ledsFinalTwo;

for (int r = 0; r < rows; r++){
            vector<int> row;
            for (int c = 0; c < cols; c++){
                row.push_back(rand()%(255-0 + 1) + 0);
            }
            ledsFinalTwo.push_back(row);
        }

when I attempt to read the values and flip them, is where I run into the error:

Subscripted value is not an array, pointer, or vector

The code causing this error is:

for (int r = 0; r < rows; r++){         //flip 2d array
                for (int c = 0; c < cols; c++){
                    if (ledsFinalOne[r][c] == 1){    //<--- error occurs here
                        ledsFinalOne[r][c] = 0;      //<--- error occurs here
                    } else {
                        ledsFinalOne[r][c] = 1;      //<--- error occurs here
                    }
                }
            }

btw I am using namespace std - if that makes any differeence

Thanks for the help / suggestions in advance.

Aucun commentaire:

Enregistrer un commentaire