Dec 25, 2013 at 9:10pm UTC
It's a 2D vector. Just like a 2D array.
Dec 26, 2013 at 2:57pm UTC
Sorry for my late reply. I still don`t understand as i donno 2d arrays or even arrays :-/
Dec 26, 2013 at 3:55pm UTC
They're not really required to be learned. They are just arrays of arrays.
http://www.cplusplus.com/doc/tutorial/arrays/
Dec 26, 2013 at 3:59pm UTC
A vector of vectors also can have rows of unequal sizes.
Dec 26, 2013 at 4:19pm UTC
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:
1 2 3 4 5 6 7 8
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#include <iostream>
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 Dec 26, 2013 at 4:21pm UTC
Dec 29, 2013 at 1:33pm UTC
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