### What is a vector <vector<int>>

closed account (EwCjE3v7)
What is a
 `` `` `` vector > ivv;``

I know what a `vector <int> iv;` but what is `vector <vector<int>>`

Thanks
It's a 2D vector. Just like a 2D array.
 It's a 2D vector. Just like a 2D array.

Just a small observation: a plain 2D array looks like a matrix, because all rows have equal lengths.

However with a vector of vectors, you need to make sure personally that this is so:

 ```int a[3][4]; [[xxxx] [xxxx] [xxxx]] vector > vvi; [ ] vector > vvi(3); [[] [] []] vector > vvi(3, vector(4)); [[xxxx] [xxxx] [xxxx]] ```
closed account (EwCjE3v7)
Sorry for my late reply. I still don`t understand as i donno 2d arrays or even arrays :-/
They're not really required to be learned. They are just arrays of arrays.

http://www.cplusplus.com/doc/tutorial/arrays/
A vector of vectors also can have rows of unequal sizes.
You need to learn arrays first and then multi-dimensional arrays. An array is just like a collection of stuff of the same data type.

Here is a crash-course for you:

You declare an array like this:
`data_type arrayname[ARRAY_SIZE];`

An example:
`int numbers[5]; //This creates an array of type int to store 5 integers `

Indexing of the array starts at 0 and ends at ARRAY_SIZE-1.

If I have an array of size 5, the first element would be at index 0, the second would be at index 1 and the last element at index 4 (5-1).

You access an element in the array with `array_name[index];`.

An array's size cannot be changed once declared.

A 2D array is basically an array of arrays. You declare it like this `type array_name[siz_x][siz_y];`;

It looks like this:
 ``12345678`` ``````int myarray[3][3]; /* If you fill the above with zeroes it'd look like: [[0,0,0], [0,0,0], [0,0,0]] */``````

An example program using array:
 ``123456789101112131415161718192021222324252627`` ``````#include int main() { int userInputs[5]; int sum = 0; std::cout << "Enter a number: "; std::cin >> userInputs[0]; for(int i = 1; i<5; i++) { std::cout << "Enter another number: "; std::cin >> userInputs[i]; } for(int j = 0; j<5; j++) { sum += userInputs[j]; } std::cout << "The sum of those numbers are: " << sum << std::endl; return 0; }``````

Last edited on
closed account (EwCjE3v7)
Thanks guys, I'll learn arrays once they come in my book even tho I think I know most because of Stormboy. Thank you all great help
Topic archived. No new replies allowed.