Assigning a new string crashes?
<p>I'm trying to write my first real program with dynamic arrays, but I've come across a problem I cannot understand.  Basically, I am trying to take a dynamic array, copy it into a temporary one, add one more address to the original array, then copy everything back to the original array. Now the original array has one more address than before. This worked perfectly when trying with ints, but strings crash my program. Here's an example of the code I'm struggling with:</p>

<pre><code>void main()
{
int x = 3;
std::string *q;
q = new std::string[x];

q[0] = "1";
q[1] = "2";
q[2] = "3";

    x++;
    std::string *temp = q;
    q = new std::string[x];
    q = temp;
    q[x-1] = "4";

    for (int i = 0; i &lt; 5; i++)
    std::cout &lt;&lt; q[i] &lt;&lt; std::endl;
}
</code></pre>

<p>If I were to make q and temp into pointers to int instead of string then the program runs just fine. Any help would be greatly appreciated, I've been stuck on this for an hour or two. </p>