Computing.Net > Forums > Programming > C++ and Arrays

C++ and Arrays

Reply to Message Icon

Original Message
Name: ssjheero_yuy99
Date: September 5, 2006 at 08:56:18 Pacific
Subject: C++ and Arrays
OS: Win XP Pro SP2
CPU/Ram: 1GB DDR
Model/Manufacturer: Systemax
Comment:

Hello,

I am just learning C++, I have already learned the concepts through Object Pascal and am now moving onto C++.

My question deals with arrays, specifically dynamic arrays. (please note I might be using Pascal terms).

I have a program that takes and inputs integers from the command line, however, this input stream can be as large or as small as the user wants it to be.

What I want to do is create a dynamic array for the stream to drop the values into so that I can remember the values that were entered into the input stream for later manipulation.

I know in Pascal I could create a dynamic array with no size or any size, then later in the program extend or decrease the length of the array at will. using the setlength(<arrayname>, <arraysize> ); command.

What I am wondering is if there is the a way to do this same thing in C++, so that I don't have to have an array that is infinitly big to start with.

Thanks for your help and for reading!


Report Offensive Message For Removal


Response Number 1
Name: siteforge (by Greg Apel)
Date: September 5, 2006 at 14:52:14 Pacific
Reply: (edit)

As far as I understand, there's no quick & skinny method in C++ for redimensioning arrays.

C# can do it pretty easilly, as well as VB

C#: ReDimension(OldArray, 20);
VB: ReDim myArray(20)

You may want to look into C++ vectors - seems to be able to do what you need: http://www.codersource.net/c++_vector_stl.html


Report Offensive Follow Up For Removal

Response Number 2
Name: ssjheero_yuy99
Date: September 5, 2006 at 18:46:38 Pacific
Reply: (edit)

Thanks for the help Siteforge.

I believe that will do it.

Thanks!


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: C++ and Arrays

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes Today.
Discuss in The Lounge