GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 17-Mar-2004, 22:05
Lethal411 Lethal411 is offline
New Member
 
Join Date: Mar 2004
Posts: 1
Lethal411 is on a distinguished road

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  
Old 17-Mar-2004, 22:25
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
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  
Old 20-Mar-2004, 09:02
machinated machinated is offline
Regular Member
 
Join Date: Mar 2004
Location: victoria, canada
Posts: 324
machinated has a spectacular aura aboutmachinated has a spectacular aura about
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:
Originally Posted by Lethal411
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
 
 

Recent GIDBlogToyota - 2008 September Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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

All times are GMT -6. The time now is 19:41.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.