fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int size = 1;
  8.  
  9. double* temperatur = new double[size];
  10. double* temperatur_save; // don't allocate memory for this pointer.
  11.  
  12. for (int i = 0; i < 40; i++)
  13. {
  14.  
  15. temperatur[i] = i;
  16.  
  17. //save temperatur array in temperatur_save
  18. temperatur_save = temperatur;
  19.  
  20. //Create a new array with larger size
  21. temperatur = new double[size + 1];
  22.  
  23. //Copy the saved values to this array
  24. for ( int j = 0; j < size; j++ )
  25. temperatur[j] = temperatur_save[j];
  26.  
  27. //Free unused memory
  28. delete [] temperatur_save;
  29.  
  30. //Display values
  31. cout << temperatur[i];
  32.  
  33. //Increase "size" by one
  34. size++;
  35.  
  36. }
  37.  
  38. // don't use the risky, platform dependent system commands.
  39. cin.get();
  40. }
  41.  
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
0123456789101112131415161718192021222324252627282930313233343536373839