Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Dynamic array and table?

Reply
Thread Tools

Dynamic array and table?

 
 
saneman
Guest
Posts: n/a
 
      08-11-2008
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?


 
Reply With Quote
 
 
 
 
mlimber
Guest
Posts: n/a
 
      08-11-2008
On Aug 11, 8:49*am, "saneman" <(E-Mail Removed)> 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?


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-lit...html#faq-16.17

Cheers! --M
 
Reply With Quote
 
 
 
 
saneman
Guest
Posts: n/a
 
      08-11-2008

"Victor Bazarov" <(E-Mail Removed)> skrev i en meddelelse
news:g7pd03$i60$(E-Mail Removed)...
> 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



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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
const and array of array (of array ...) Mara Guida C Programming 3 09-03-2009 07:54 AM
Array question - How dynamic is dynamic? Ruby Student Ruby 4 04-09-2009 12:59 PM
access object in array of pointers to dynamic array of class complex jccorreu@gmail.com C++ 2 05-20-2006 05:08 AM
Convert Static Array to Dynamic Array ? raxitsheth@gmail.com C Programming 2 07-14-2005 01:25 AM
Can a static array contain a dynamic array of pointers? Peter B. Steiger C Programming 8 04-26-2004 03:07 AM



Advertisments