0

以下に示す while ループで istringstream を続行するのに問題があります。データファイルも以下に示します。入力ファイルから getline を使用して最初の行を取得し、それを istringstream lineStream に入れます。while ループを 1 回通過した後、2 行目を読み込んでループの先頭に戻り、ループを続行せずに終了します。理由はわかりませんが、誰かが助けてくれたらありがたいです。編集: この while ループ条件がある理由は、ファイルに誤ったデータの行が含まれている可能性があるためです。したがって、私が読んでいる行がデータファイルで以下に示す適切な形式であることを確認したいと思います。

while(lineStream >> id >> safety){//keeps scanning in xsections until there is no more xsection IDs

    while(lineStream >> concname){//scan in name of xsection
        xname = xname + " " +concname;
    }


    getline(InputFile, inputline);//go to next xsection line
    if(InputFile.good()){
        //make inputline into istringstream
        istringstream lineStream(inputline);
        if(lineStream.fail()){
            return false;
        }
    }
}

データファイル

4   0.2  speedway and mountain
7   0.4 mountain and lee
6   0.5 mountain and santa
4

1 に答える 1