473,327 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Resizable Arrays

dms
Hi,

Is there another, more friendly way to create resizable arrays without
using the realloc function?

Thanks

David Sharp

Jul 19 '05 #1
4 2157
> Is there another, more friendly way to create resizable arrays without
using the realloc function?


Take a look at the std::vector class in the standard library. This class
is an excellent replacement for C-style arrays in most cases.

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl
Jul 19 '05 #2
dms
Hi,

Thanks for the quick reply. Can you please give me an example of usage?

Thanks

David Sharp

Peter van Merkerk wrote:
Is there another, more friendly way to create resizable arrays without
using the realloc function?

Take a look at the std::vector class in the standard library. This class
is an excellent replacement for C-style arrays in most cases.

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl


Jul 19 '05 #3
> Thanks for the quick reply. Can you please give me an example of
usage?

#include <iostream>
#include <vector>

using namespace std;

int main()
{
vector<int> v(3); // Create vector with 3 default constructed
elements.

v[0] = 100;
v[1] = 200;
v[2] = v[1] + v[0];

v.push_back(123); // Add one element to the v, v now has 4 elements.
v.push_back(321); // Add one element to the v, v now has 5 elements.

v.resize(10); // Resize v to 10 elements
v[9] = 12345; // Set value of last element of v

// Dump contents of v
for(int i=0; i < v.size(); ++i)
{
cout << "v[" << i << "] = " << v[i] << endl;
}
return 0;
}
HTH

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl

Jul 19 '05 #4
dms
That's great! Thanks.

Peter van Merkerk wrote:
Thanks for the quick reply. Can you please give me an example of


usage?

#include <iostream>
#include <vector>

using namespace std;

int main()
{
vector<int> v(3); // Create vector with 3 default constructed
elements.

v[0] = 100;
v[1] = 200;
v[2] = v[1] + v[0];

v.push_back(123); // Add one element to the v, v now has 4 elements.
v.push_back(321); // Add one element to the v, v now has 5 elements.

v.resize(10); // Resize v to 10 elements
v[9] = 12345; // Set value of last element of v

// Dump contents of v
for(int i=0; i < v.size(); ++i)
{
cout << "v[" << i << "] = " << v[i] << endl;
}
return 0;
}
HTH

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl


Jul 19 '05 #5

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

Similar topics

4
by: VR | last post by:
First, greetings to everyone :) I'm doing a university seminar & I've encountered a problem. I have a gallery with thumbnails linked on pictures. What I want is popup to be opened with...
4
by: sam.s.kong | last post by:
Hello! I opened a new window using 'resizable=no'. Can the child window make itself resizable even if it's opened with 'resizable=no'? For example: <body onload="javascript:...
19
by: Mark | last post by:
i need to make a class that can store anything (integers,objects,etc) it needs to maintain a list of pointers to these objects the list needs to be resized to accomodate more elements i can't use...
3
by: Al Henderson | last post by:
Morning All, I have a web application where we pop up a little calendar control in a new window to allow users to choose dates. For cross-browser purposes, this is done via window.open (with...
3
by: Anupama | last post by:
Is it possible that first I make my window resizable,than if window is less than a fixed size I can make my window not resizable?Better to say can I change resizable feature during runtime?If...
11
by: Aaron Gray | last post by:
Hi, I have put together a bit of JavaScript to make a square resizable canvas :- http://www.aarongray.org/Test/JavaScript/resizable.html Problems I have :- a) I cannot seem to center it...
3
by: guarumal | last post by:
Hi, I am try to make a window resizable but it does not work. I am using in the child window <body onload="javascript: window.resizable=true;"> What else can I do?
3
by: Thierry Loiseau | last post by:
Hello, If I do : w=window.open('','a','resizable=no, width=400, height=400, toto=3'); can I modify 'w' to resizable=yes ? Thank you, Thierry
1
by: since | last post by:
I figured I would post my solution to the following. Resizable column tables. Search and replace values in a table. (IE only) Scrollable tables. Sortable tables. It is based on a lot...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.