Jump to content
  • Advertisement
Sign in to follow this  
raptorstrike

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.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by raptorstrike
on 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 this post


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


// declare
vector< vector<type_name> > some_vector;

// access
some_vector[col][row]
some_vector.at(col).at(row)

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!