Reading CSV data from a file
<p>I'm sorry if this has been asked, but I can't seem to find a solution that helps me.  I'm trying to read in data from a text file, and ultimately store it in an object.</p>

<p>The text file has 4 variables all separated with commas.</p>

<p>I've tried to do this as follows:</p>

<pre><code>string v1, v2, v3, v4;
ifstream afile;
afile.open("thefile.txt");
afile &gt;&gt; v1 &gt;&gt; v2 &gt;&gt; v3 &gt;&gt; v4;
afile.close();
cout &lt;&lt; v1 &lt;&lt; endl;
cout &lt;&lt; v2 &lt;&lt; endl;
cout &lt;&lt; v3 &lt;&lt; endl;
cout &lt;&lt; v4 &lt;&lt; endl;
</code></pre>

<p>The file has multiple records.  I have tried to just do 1 for now to makes sure it works, but when it reads in the data, it doesn't separate at the commas.</p>

<p>From there, I want to store the data into an object.  Will the following work:
    Thing* thing1 = new Thing(v1, v2, v3, v4);</p>

<p>Although, when I read in say 5 records, what would be the best way to structure the above line of code?  As each object needs a unique name, is there a way I could iterate perhaps using a for loop and a vector? ie
    for (int i = 0; i &lt; 5; i++) {
        // read in data
        // store in vector
    }</p>

<p>Any hints are very much appreciated</p>
