If you want to create your own class, its faster for resizing to:
1: Create a new array of whatever size you want.
2: Copy all values from Old Array into the new array.
3: Delete old array.
4: Reset old array pointer to new array pointer.
The STL vector is the same thing as what you want. #include <vector> (no ".h"). For example:
This should work (except for the ...resize(50000...) line =).Code:#include <vector> #include <iostream.h> void main() { std::vector<int> SomeVector; SomeVector.resize(50000000000); // i dunno =) SomeVector.resize(0); SomeVector.push_back(10); // inserts a 10 as the last item cout << SomeVector[0] << endl; //a 10 SomeVector.push_back(55); cout << SomeVector[1] << endl; // a 55; SomeVector.resize(10); for(int i = 2; i < SomeVector.size(); i++) { SomeVector[i] = i; } for(i = 0; i < SomeVector.size(); i++) cout << SomeVector[i]; return; }
Z.




Reply With Quote