title: What is C++ version of realloc(), to allocate the new buffer and copy the contents from the old one?
body: <p>In C we used <code>malloc(), free()</code>, but in C++ youare using <code>new, delete</code>, but in C we also have <code>realloc</code>, which will alloc the new block and copy the old data (common minimum) and then free the old data bock. So what is the C++ version of that? I can write my own of course, but is there a builtin thing?</p>
  
  <pre><code>main() {
    int i; char *x = malloc(3);
    x[0] = 10;
    x[1] = 20;
    x[2] = 30;
    realloc(x, 4);
    x[3] = 40;
    for (i = 0; i &lt; 4; i++) printf("%i\n", x[i]);
  }
  </code></pre>