|
-
Sep 1st, 2001, 05:15 AM
#1
Dynamica arrays in C
hi ppl,
i know there's a lot of talent out there, so i am challenging UR talent. HA HA HA ....
is there any way to simulate dynamic arrays in C, or C++.
i really need that..
and hay , not the linked lists and other things,,,, some piece of code that can enable me to make dynamic arrays just like i do it in VB.......( who says C language is powerful ).
Salman.
-
Sep 1st, 2001, 05:57 AM
#2
Frenzied Member
To dynamically allocate an array (at rub time):
Code:
int myarray = new int[size];
To change the array size in runtime use the vector class.
-
Sep 1st, 2001, 10:06 AM
#3
The vector can also be used to do preserve the data.
Code:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> myVect;
// Append 4 and 5
myVect.push_back(4);
myVect.push_back(5);
// Resize to 20;
myVect.resize(20);
// Output the ubound
cout << myVect.size();
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|