Dynamic array and table?

Discussion in 'C++' started by saneman, Aug 11, 2008.

  1. saneman

    saneman Guest

    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];

    where a and b change be set during runtime and the size og M can vary, is
    that possible?
     
    saneman, Aug 11, 2008
    #1
    1. Advertising

  2. saneman

    mlimber Guest

    On Aug 11, 8:49 am, "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];
    >
    > 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:

    http://www.parashift.com/c -faq-lite/freestore-mgmt.html#faq-16.17

    Cheers! --M
     
    mlimber, Aug 11, 2008
    #2
    1. Advertising

  3. saneman

    saneman Guest

    "Victor Bazarov" <> skrev i en meddelelse
    news:g7pd03$i60$...
    > 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];
    >>
    >> 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.
     
    saneman, Aug 11, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick Glos
    Replies:
    0
    Views:
    648
    Rick Glos
    Jul 8, 2003
  2. David Williams
    Replies:
    2
    Views:
    1,140
    Jacob Yang [MSFT]
    Aug 12, 2003
  3. =?Utf-8?B?QkxpVFpXaU5H?=

    Adding dynamic LinkButton to dynamic table

    =?Utf-8?B?QkxpVFpXaU5H?=, Jul 27, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    734
    =?Utf-8?B?QkxpVFpXaU5H?=
    Jul 27, 2005
  4. opius
    Replies:
    0
    Views:
    1,184
    opius
    Jun 17, 2011
  5. Kooki

    Dynamic Table with Dynamic Button inside

    Kooki, Sep 15, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    153
    Kooki
    Sep 15, 2005
Loading...

Share This Page