Dynamic array and table?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • saneman

    Dynamic array and table?

    std::vector<int v creates a dynamic array where its possible to insert new
    elements without doing any preallocation. But how about a dynamic double
    array? I would like to have something like:


    int M[a][b];

    where a and b change be set during runtime and the size og M can vary, is
    that possible?


  • mlimber

    #2
    Re: Dynamic array and table?

    On Aug 11, 8:49 am, "saneman" <as...@asd.comw rote:
    std::vector<int v creates a dynamic array where its possible to insert new
    elements without doing any preallocation. But how about a dynamic double
    array? I would like to have something like:
    >
    int M[a][b];
    >
    where a and b change be set during runtime and the size og M can vary, is
    that possible?
    Try:

    std::vector< std::vector<int M;

    Depending on your application, there may be better ways to do it. See
    also this FAQ and following:



    Cheers! --M

    Comment

    • Victor Bazarov

      #3
      Re: Dynamic array and table?

      saneman wrote:
      std::vector<int v creates a dynamic array where its possible to insert new
      elements without doing any preallocation. But how about a dynamic double
      array? I would like to have something like:
      >
      >
      int M[a][b];
      >
      where a and b change be set during runtime and the size og M can vary, is
      that possible?
      It's not exactly equivalent, but you could try to get away with

      std::vector<std ::vector<int M(a, std::vector<int >(b));

      V
      --
      Please remove capital 'A's when replying by e-mail
      I do not respond to top-posted replies, please don't ask

      Comment

      • saneman

        #4
        Re: Dynamic array and table?


        "Victor Bazarov" <v.Abazarov@com Acast.netskrev i en meddelelse
        news:g7pd03$i60 $1@news.datemas .de...
        saneman wrote:
        >std::vector<in tv creates a dynamic array where its possible to insert
        >new elements without doing any preallocation. But how about a dynamic
        >double array? I would like to have something like:
        >>
        >>
        >int M[a][b];
        >>
        >where a and b change be set during runtime and the size og M can vary, is
        >that possible?
        >
        It's not exactly equivalent, but you could try to get away with
        >
        std::vector<std ::vector<int M(a, std::vector<int >(b));
        >
        V
        --
        Please remove capital 'A's when replying by e-mail
        I do not respond to top-posted replies, please don't ask

        Seems that boots:ublas has some dynamic vectors and matrices that I can use.


        Comment

        Working...