![]() |
|
#1
|
|||
|
|||
Declaring a vector of vectors?Does anyone know how to declare a vector of vectors?
I need to declare a vector for the columns and then a row. Is this the easiest way to do 2-d storage only using vectors? This is what I have so far and it compiles but will not let me access it with the push_back method: typedef vector <int> columns; vector <columns> rows; Now how would I put information in to these variables? Thanks |
|
#2
|
||||
|
||||
|
If vector<int> declares a vector of ints, shouldn't vector<vector> declare a vector of vectors? Also, I don't believe you can typedef a vector in the format "vector <int>," where there's a space between "vector" and "<int>", because I'm pretty sure the C language only accepts three fields for the typedef statement. typedef type_to_use name_of_new_type.
__________________
-Aaron |
|
#3
|
|||
|
|||
|
This is how u would declare a 2 dim vector:
vector < <vector <int> >matrix; (make sure you have spaces jus like i did) altho i do believe that with multidimensional vectors you need to create rows and then assign values with push_back(); for example matrix.push_back(vector <int>()); would create the row matrix[0] and so on. to assign values: jus go matrix[0].push_back(50); which assigns 50 to matrix[0][0]. You can access the elements in regular fashion: matrix[0][0]; matrix[1][0]; and so on. do some experimenting with this till you are comfortable. Quote:
|
Recent GIDBlog
Toyota - 2008 September Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C++ Vectors | Katie | C++ Forum | 5 | 17-May-2004 23:36 |
| help with c++ vectors | beebop | C++ Forum | 1 | 12-Mar-2004 06:03 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The