Skip to main content
gamedev.net
🔒 Locked

2 dimensional vector?

Started by Skkra Aug 10, 2002 at 9:17 AM 2 replies 200+ views
Original Post
Skkra
Skkra
I''ve been trying to get a 2 dimensional vector of integers in an array-type format but am not sure how to do this. I know you can do things like: int *words; words = new int[5]; However, you cannot do words = new int[4][4]; because it bombs out. I''ve decided to go with vectors for this because I need something I can resize easily. Does anyone know how to create a 2-d vector period? Doesnt even have to be with pointers. If anyone could help me out I''d be greatly appreciative!!! Thanks, Skkra
mentat
mentat


    
// creation..

int size = 4;
int ** words = 0;
words = new int*[size];
for (int i = 0; i < size; ++i)
words[i] = new int[size];



//destruction..

for (int i = 0; i < size; ++i)
delete []words[i];
delete []words;


[edited by - mentat on August 10, 2002 10:37:12 AM]
-----------my quote is under construction
SabreMan
SabreMan

    
#include <iostream>

#include <vector>


int main()
{
std::vector<std::vector<int> > vect_of_vects;
std::vector<int> vect1;
vect1.push_back(0);
vect1.push_back(1);
vect1.push_back(2);

vect_of_vects.push_back(vect1);
// ... you get the picture ...

}


Also, read Marshall Cline's notes on why arrays are evil.

[edited by - SabreMan on August 10, 2002 10:51:18 AM]
Skkra
Skkra
Thank you very much!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.