Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

dynamic two dimensional array

array dynamic multidimensional

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1 JonElias

JonElias

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 201 posts

Posted 18 July 2015 - 01:47 AM

is it possible to make a dynamic two dimensional array in c++.

i know that i would need a vector array because it is dynamic, but how do i make it multidimensional


"computers are useless they only give you answers" Pablo Picasso
And yes he was alive when the first programmable computer was made

#2 0xDEADBEEF

0xDEADBEEF

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 790 posts

Posted 18 July 2015 - 01:10 PM

Declare a vector of vectors (or a vector of pointers to vectors.)


Creating SEGFAULTs since 1995.


#3 Sessions1024

Sessions1024

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 01 September 2015 - 07:16 PM

vector<pair<string, int>> DemoVector;

Maybe try something like this



#4 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts

Posted 02 September 2015 - 07:26 PM

You'll want something like:

std::vector<std::vector<whatever_data_type_you_want> >

Notice that the space between the closing '>' is required in C++ before C++11, because compliant compilers will confuse it with the bit shift right operator (>>). This restriction is lifted in C++11.


sudo rm -rf / && echo $'Sanitize your inputs!'





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download