title: Dynamic Arrays
body: <p>I'm just starting to learn C++ so excuse me for this simple question. What I'm doing is reading in numbers from a file and then trying to add them to an array. My problem is how do you increase the size of the array? For example I thought might be able to just do:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main() {
      double *x;
      x = new double[1];
      x[0]=5;
      x = new double[1];
      x[1]=6;
      cout &lt;&lt; x[0] &lt;&lt; "," &lt;&lt; x[1] &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>But this obviously just overwrites the value, 5, that I initially set to x[0] and so outputs 0,6. How would I make it so that it would output 5,6?<br /><br />Please realize that for the example I've included I didn't want to clutter it up with the code reading from a file or code to get numbers from a user. In the actual application I won't know how big of an array I need at compile time so please don't tell me to just make an array with two elements and set them equal to 5 and 6 respectively.<br /><br />Thanks for your help.</p>