Reading separated columns in a CSV file in C++ using getLine
<p>I have a program that can successfully read a CSV file. The said CSV file is a list separated by 3 columns. And each column has a comma in between each line. For instance</p>

<p>line 1 --- artist, genre, song
line 2 --- Michael jackson, Pop, thriller</p>

<p>and so on. What I want my program to do is read the first line and to take artist, genre, and song, print those out to the user as options. For instance</p>

<p>"Choose an Option"
1. Artist
2. Genre
3. Song</p>

<p>and then when they select an option it then shows them either all the artists, songs, or genres in the CSV file.</p>

<p>So far I have my program reading the CSV and putting each line in a vector. Here is my code so far ...</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;sstream&gt;
#include &lt;string&gt;
#include &lt;fstream&gt;
#include &lt;vector&gt;
using namespace std;
int main()
{
    ifstream infile("music_list.csv");
    string line = "";
    vector&lt;string&gt; all_words;
    cout &lt;&lt; "Hello";
    while (getline(infile, line))
    {
        stringstream strstr(line);
        string word = "";
        while (getline(strstr,word, ','))
        {
            all_words.push_back(word);
        }

        for (unsigned i = 0; i &lt; all_words.size(); i++)
        {
            cout &lt;&lt; all_words.at(i)&lt;&lt; "\n";
        }

    }
    system("pause");
    return 0;
}
</code></pre>

<p>I'm just having trouble figuring out how to have it read the first line, separate each string in the first line that is already separated by a comma and have that then outputted to the user as an option. So in essence I can change artist, genre, song to something like appetizers, dish, drinks in the CSV file.</p>
