   Increasing the size of an array
  Hi Guys,Is there a way to increase the size of an array within the program itself?For example, turn test[10] into test[10000] during program execution.Because each array will be computationally expensive I dont want to have a large array by default, but have to option to do so, while the program is running - without upsetting the contents of the previous arrays.Can this be done?   
  Assuming C++, use a std::vector.;  This is the purpose of a vector, to work like an array that can change size as needed. Here's an example:#include <iostream>#include <vector>using namespace std;int main(){    vector<int> numbers;    for(int i=1; i<=10; i++)   numbers.push_back(i);    cout << "the vector numbers is now " << numbers.size() << " items" << endl;    for(int i=1; i<10000; i++)   numbers.push_back(i);    cout << "numbers now contains " << numbers.size() << " elements" << endl;    cout << numbers[2] << " " << numbers[3000] << " " << numbers[10000];};  Thanks, I'll look into that.I haven't used the stl library much. So, I'll have to brush up. :)So, this can be used for an array of structs too?   ;Quote:Original post by lonewolffSo, this can be used for an array of structs too?Anything; hence the template.  Just be aware that when the vector needs to resize the array, operator= is called to copy elements from the old array to the new array.  Be sure that your custom class obeys the rule of three.   ;  I think I have this more or less worked out but am unsure of how to get the values back out.#include<cstdlib>#include<iostream>#include<vector>using namespace std;struct Test{int nItem1;int nItem2;};using namespace std;int main(){Test something;something.nItem1=1;something.nItem2=2;vector<struct Test>(tt);tt.push_back(something);something.nItem1=3;something.nItem2=4;tt.push_back(something);vector<Test>::iterator it;for(it=tt.begin();it<tt.end();it++){// *** How do I get values for nItem1 & nItem2?}system("PAUSE");return 0;}How do I get values for nItem1 & nItem2?;  Worked it out. All goodit->nItem1 etc...Thanks for your help on this guys!   ;  The C++ standard library has a concept of iterators that you should get comfortable with. It lets you use and write highly re-usable and generic code.That is, in for(it=tt.begin();it<tt.end();it++){}it points to an element within tt (read that article I linked to). You can dereference the pointee by using operator*:for(it=tt.begin();it<tt.end();it++){    (*it).nItem1 = 42;}