I know its 9 rows now, but I dont have variable to know that |
With a C++ vector there is no need to have a separate variable, just use the container's size() member method. So you don't have to know what the size of the container is until you have a need to know.
I dont use vectors, I just use simple C array[1000] |
Unless you write C code you should use a C++ container. C++ has fixed and dynamic sized containers. Managing the dimension(s) and memory for you.
std::array is a bit of a peculiar duck compared to the other containers, a wrapper around a C style array so it has a common interface with the other containers.
Using a C array will complicate the code needed to programmatically figure out the number of entries, either rows or columns. Especially complicated is passing a 2D array into a function, the array devolves to a pointer making it hard to know the sizes without passing them as parameters.
Or some other scheme that uses 'sentinel values,' a C string uses the NULL character, '\0', for that.
A C++ container retains the ability to query the size(s) of the container after being passed into a function.
With a 2D std::vector it is easy to query the number of of rows, and the number of entries/columns in each row, using vector's member size() method. Using std::vector makes it easy to have a 'ragged' 2D layout. Each row potentially can have a differing number of columns.