Public Group

2d Vector??

This topic is 5403 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

basicly dose such a thing exist? dose it need to? if not what can i do thats like it. thanks

Share on other sites
Yes, of course. A vector can have any number of dimensions. Otherwise it would be difficult to talk about 2D geometry.

Share on other sites
i think he means a std::vector.

vector < vector < Type > > variable_name;

the spaces between the > > is important.. otherwise the compiler will think your bit shifting.

Share on other sites
yes a std::vector is what im talking about ok thanks for the answer
[grin]

Share on other sites
ps. Why do we even use arrays there so out of date

Share on other sites
on a simeler note why donst this work
vector<const char*> szFiles(64); szFiles = {"0.bmp","1.bmp","2.bmp","3.bmp","4.bmp","5.bmp","6.bmp","7.bmp","8.bmp","9.bmp","10.bmp","11.bmp","12.bmp","13.bmp","14.bmp","15.bmp","16.bmp","17.bmp","18.bmp","19.bmp","20.bmp","21.bmp","22.bmp","23.bmp","24.bmp","25.bmp","26.bmp","27.bmp","28.bmp","29.bmp","30.bmp","31.bmp","32.bmp","33.bmp","34.bmp","35.bmp","36.bmp","37.bmp","38.bmp","39.bmp","40.bmp","41.bmp","42.bmp","43.bmp","44.bmp","45.bmp","46.bmp","47.bmp","48.bmp","49.bmp","50.bmp","51.bmp","52.bmp","53.bmp","54.bmp","55.bmp","56.bmp","57.bmp","58.bmp","59.bmp","60.bmp","60.bmp","60.bmp","64.bmp"};

and how can i do somthing like it

Share on other sites
Correct me if I'm wrong, but you're trying to give values to a constant char*, which you can't do, I think.

Share on other sites
Quote:
 Original post by raptorstrikeon a simeler note why donst this work*** Source Snippet Removed ***and how can i do somthing like it

First of all, the elements of the vector are constant, so there would be no modifying them at all.

Second, you can't assign multiple values to a vector. You may have seen that work with a regular old array. You can do what you're trying to do three ways (I'm sure there are more, but here's three.)

1)
vector<char*> szFiles(64)szFiles[0] = "0.bmp";szFiles[1] = "1.bmp"...

2)
vector<char*> szFiles;szFiles.push_back("0.bmp");szFiles.push_back("1.bmp");...

3)
vector<char*> szFilesVec;char* szFiles[] = {"0.bmp","1.bmp","2.bmp","3.bmp","4.bmp","5.bmp","6.bmp","7.bmp","8.bmp","9.bmp","10.bmp","11.bmp","12.bmp","13.bmp","14.bmp","15.bmp","16.bmp","17.bmp","18.bmp","19.bmp","20.bmp","21.bmp","22.bmp","23.bmp","24.bmp","25.bmp","26.bmp","27.bmp","28.bmp","29.bmp","30.bmp","31.bmp","32.bmp","33.bmp","34.bmp","35.bmp","36.bmp","37.bmp","38.bmp","39.bmp","40.bmp","41.bmp","42.bmp","43.bmp","44.bmp","45.bmp","46.bmp","47.bmp","48.bmp","49.bmp","50.bmp","51.bmp","52.bmp","53.bmp","54.bmp","55.bmp","56.bmp","57.bmp","58.bmp","59.bmp","60.bmp","60.bmp","60.bmp","64.bmp"};for (int i=0; i<64; ++i)  szFilesVec.push_back(szFiles);

Share on other sites
I think what you're asking for is a vector of vectors, which you can do.

// declarevector< vector<type_name> > some_vector;// accesssome_vector[col][row]some_vector.at(col).at(row)

Share on other sites
first of all, stop using char*'s to represent a string. using a char* with a std::vector, is like buying a brand new super fast computer and hooking it up to a dial up modem. ok, thats a bad analogy, but you get the point. if your going to use the std library, then make use of the whole thing. change that to

vector<string> szFiles;

secondly, i don't know if you read my other post in your old thread, so im going to re-post it here:

btw, you can replace that really ugly handmade array called *szFiles[64]. you can do all this with a loop.

for(int i = 0; i < 10; i++){	szFiles = Int_To_String(i + 1) + ".bmp";}

where Int_To_String is:

string Int_To_String(int num){        //if this is happening, im screwing up somewhere.....        assert(number <= 9999999999);        char buffer[10];		stringstream ss;		ss << num;	strcpy(buffer, ss.str().c_str());	return buffer;}

btw, you should probably make that int a templated parameter. this way you can send it floats or anything else you need... i didnt want to confuse you though.

also, you should definetly use a std::string isntead of an array of pointers... if a function IMG_Load takes a const char*, you can convert a string to this by doing stringname.c_str().

one last thing i would like to add, you should get into the habit of NOT using "using namespace std". i didn't, and now i have 10,000+ lines of code which is "using namespace std"... im not looking forward to going through that and changing it all [smile]

• 13
• 18
• 29
• 11