从文件中解析,其中一列具有多个值

时间:2014-04-18 03:44:38

标签: c++

我试图将文本文件中的信息加载到矢量中。但是,其中一列中有多个值,我在尝试从那里检索信息时遇到问题。以下是我的代码段。

文本文件的格式如下: 第一列将是名称,第二列将是他现在正在采取的所有类。对于第二列,我创建了一个向量来保存它,但我不知道如何为它做一个while循环条件。有人可以帮帮我吗?

mtingley    |art, music, math, history

while(getline(inUsers, textLine))
{
    Student s;
    string delimeter;
    // put the line into buffer string
    istringstream textStream(textLine);
    // get userName
    textStream >> userName;
    // read the buffer string till '|'
    getline(textStream, delimeter, '|');
    cout << userName << endl;
    s.SetUserName(userName);

    while() // need condition in this while loop
   {
        textStream >> subject;
        getline(textStream, delimeter, ',');
        vCourse.push_back(subject);
   }
}   

1 个答案:

答案 0 :(得分:0)