0
私はcsvファイルの2つの文字列を比較しています。 csvファイルを解析した結果、データの行がカンマで区切られています。なぜ2つの文字列を比較した結果が最後に一致した文字列を見つけられなかったのですか?
コーディングは正常に機能しますが、最後に一致した行は表示されません。
CSVファイルの内容:
Title,sn,sn,sn
test,123,344,222
test,123,344,222
test,123,344,222
test,123,344,222
test,456,677,223
test,5,4545,32
apple,23,44,22
apple,323,23,22
例えば、私のコードは、ちょうど
Title,sn,sn,sn
test,123,344,222
test,123,344,222
test,123,344,222
test,123,344,222
test,456,677,223
代わりに、
Title,sn,sn,sn
test,123,344,222
test,123,344,222
test,123,344,222
test,123,344,222
test,456,677,223
test,5,4545,32
コードとして、最後にマッチした行が不足しているの下にコンテンツを表示しました以下:
int main()
{
string line;
ifstream file("sample.csv");
if(!file)
{
cout << "Error, could not open file." << endl;
return -1;
}
while(getline(file, line))
{
stringstream ss(line);
string line2;
getline(file, line2, ',');
string str = "test";
if(line2 == str)
{
cout << line << endl;
}
}
}
ありがとう、@ 10101 =) – John5012