how to build a vector of different objects after reading a file
<p>everyone! I am new for C++ and now work on a C++ project.The whole structure has been completed.But I have been wondering about </p>

<p>how to build the vector of different objects and how to read the file since the beginning.</p>

<p>In my problem, first I have to read a txt file with readObstacles(std::istream &amp;fs) that has the following format:</p>

<blockquote>
  <p>RECTANGLE 1 2.5 2 2 0.2<br>
  CIRCLE 1 2.5 1.2<br>
  RECTANGLE 4 2 2 2 0.3   </p>
</blockquote>

<p>(each obstacle begins a new line)</p>

<p>I need to read the data information of different obstacles and store these obstacles in a vector.<br>
Class Obstacle is the base class with two sub-classes CIRCLE and RECTANGLE.<br>
I try to put the these different obstacles (that i think should have their data info) in a obstacle vector and then call the virtual function they both have.</p>

<p>Below is the code I try to do with:</p>

<pre><code>vector&lt;Obstacle&gt; obsdata; 

Myworld::readObstacles(std::istream &amp;fs)
{
    std::string shape;
    double num1,num2,num3,num4,num5;
    while(fs&gt;&gt;shape&gt;&gt;num1&gt;&gt;num2&gt;&gt;num3&gt;&gt;num4&gt;&gt;num5)
    {
        if(shape=="CIRCLE") {
            CIRCLE c;
            c.m_Xc=num1;
            c.m_Yc=num2;
            c.m_Radius=num3;       
            obsdata.push_back(c);
        }

        if(shape=="RECTANGLE") {
            RECTANGLE r;
            r.center_x=num1;
            r.center_y=num2;    
            r.width=num3;
            r.height=num4;
            r.angle=num5;
            obsdata.push_back(r);
        }
    }
}

MyWorld::writeMatlabDisplayCode(std::ostream &amp;fs)
{
    for( i = 0; i &lt; obsdata.size(); i++ )
        obsdata[i].writeMatlabDisplayCode(fs);
}
</code></pre>

<p>I know it doesn't work but i don't know what i should do.</p>

<p>Any words will help. Thanks !</p>
