Hey all. I'm trying to get dynamic memory working (im making a quick file-system based database system, and I need the dynamic alloc in there) but it doesnt seem to be working...
Right now im using this code to test (with NetBeans g++):
and this leads to the cmd to instantly crash (no error flag of a bad allocation has been sent)...Code:#include <cstdlib> #include <iostream> #include <sstream> #include <fstream> #include <string> using namespace std; int main() { int aSize = 5; string* dmt = new string[aSize]; string* temp = NULL; int i = 0; int ii = 0; ostringstream oss; while(i<=100) { oss << i; dmt[i] = oss.str(); oss.str(""); if(i>=aSize) { aSize = aSize * 2; temp = new string[aSize]; while(ii<=i) { temp[ii] = dmt[ii]; ii++; } delete dmt; dmt = temp; temp = NULL; } } for(int iii=0; iii<=100; iii++) cout << dmt[iii] << endl; return 0; }
can anyone say what I have done wrong and how to fix it?