Q: Write a program that defines a vector of pointers to strings. Read the vector, printing each string and its corresponding size.
<p>I am learning C++ and there is a question in the book.</p>

<p>Q: Write a program that defines a vector of pointers to strings. Read the vector,
printing each string and its corresponding size.</p>

<p>Code: </p>

<pre><code>vector&lt;string*&gt; v;
string str;
cout&lt;&lt;"Enter your string:"&lt;&lt;endl;

while(cin &gt;&gt; str)                            // input 
{
          string *ps=&amp;str;
          v.push_back(ps);
}

vector&lt;string*&gt;::iterator iter=v.begin();
while( iter!=v.end())                         // output
   cout&lt;&lt; **iter++&lt;&lt;" "&lt;&lt;(**iter).size()&lt;&lt;endl;
</code></pre>

<p>Error:  When I input "a sd fgh", I expect the output to be "a 1; sd 2; fgh 3"; but the output is "fgh 3; fgh 3; fgh 3."   Anyone know where is going wrong? </p>
