473,624 Members | 2,534 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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?
Aug 11 '08 #1
3 1519
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:

http://www.parashift.com/c++-faq-lit...html#faq-16.17

Cheers! --M
Aug 11 '08 #2
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
Aug 11 '08 #3

"Victor Bazarov" <v.********@com Acast.netskrev i en meddelelse
news:g7******** **@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.
Aug 11 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
17656
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to Create a Dynamic Crosstab Report PRODUCT :Microsoft Access PROD/VER:1.00 1.10 OPER/SYS:WINDOWS
7
1864
by: murrayatuptowngallery | last post by:
After a few searches & inquiries here, I have a method of generating an html table populated with results of equations that works and wasn't too far up a learning curve for me, thanks to a helpful respondent/poster here... <script type="text/javascript"> var AAA = new Array(4) AAA = 2*0.1*Math.round(10*Math.log(32)/Math.log(2)) AAA = 2*0.1*Math.round(10*Math.log(16)/Math.log(2))
3
1906
by: Brian Piotrowski | last post by:
Hi All, I've probably done this before, but for the life of me I can't remember how I did it. I need to move values from a DB table into an array to be used for other queries. The number of records will vary, so I need to make the array dynamic. Can someone remind me how I can increment the index when I write a new record? Here's a sample of the code I wrote: If rsGETKD.EOF = False Then Dim KDLOTSQ
3
2932
by: josh.kuo | last post by:
Sorry about the subject, I can't think of a better one. I recently wrote some PHP classes that I think might be of interest to this group. Since I have been reaping the benefits of reading news groups for years, I figure it's time for me to contribute a little bit back, maybe some people out there will find this useful. * Introduction This is a "how-to" style article, showing by example how to dynamically
2
7043
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs, input box for units of service, description of the service and each row has its own dropdown list of unit fees that apply. Each dynamically created row will return 3 values fee1_choice, fee1_unit and fee1_money. Note The above informaton is...
1
2176
by: Skyer | last post by:
How to write? I have write program in C language. This program contain 1 array with struct. Every element of table must be dynamic list LIFO (stack). Adding and removing struct variable from list array. My question: How to declare this table? How to begining, any ideas? struct list { int *type;
0
5277
by: Eniac | last post by:
Hi, I've been working on a custom user control that needs to be modified and the validation is causing me headaches. The control used to generate a table of 4 rows x 7 columns to display all the days in the week with dates and textboxes to fill in some data. row 1: question
0
3376
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options within options. I have everything being dynamically named from the previously dynamically named element. (I hope this makes sense.) I am not able to retrieve any of the dynamically created values. I can view them on the source page but can't pull them...
2
5017
by: englishman69 | last post by:
Hello, I have been banging my head against this one for a while... Searches online have revealed many different proposals for correcting my issue but none that I can follow! My basic situation is this, I have a page which uses multiple postbacks to generate a list of dynamic text boxes with appropriate labels. However, when I do the final postback to enter the values in the dynamic textboxes into the database the values seem to become...
1
2745
by: superdad | last post by:
Hello; I have 2 questions: 1- I know you can allocate memory to an array dinamically in C and C++. But, can this be done if the array is part of a structure? 2- Can the size of a dynamic array automatically grow up to a maximum or do you have to increase it when needed yourself? This is my exact problem: I want to have a table of a fixed number of rows like 30. These are for example nodes in a comupter network. Now, for each node, I...
0
8231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8168
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8614
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8330
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4167
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2603
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1474
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.