逗号分隔的字符串流错误。它还将'-'分开

comma separated stringstream error. it also separates '-'

本文关键字:分开 分隔 字符串 错误      更新时间:2023-10-16

以下是我要保存在数组中的一组数据,使用C 。

3110,300,15500,1,2017-11-29,8835,010-9033-1234
3110,396,530,1,2017-11-29,8835,010-9033-1234
3110,401,450,2,2017-11-29,8835,010-9033-1234

我使用以下帮助来做到这一点。如何使用弦乐分开逗号分隔字符串但是我遇到了两个问题。日期保存为:

2017

,电话号码保存为:

10

相反,我希望将它们都保存为字符串。

2017-11-29
010-9033-1234

以下是我制作的代码:

while (fileIN.good()) {
    while (getline(fileIN, lineA)) {
        cout << lineA << endl;
        istringstream ss(lineA); colA = 0;
        while (getline(ss, token, ',')) {
            if (colA = 0) { Data[rowA].price = stoi(token); cout << Data[rowA].price << endl; }
            else if (colA = 1) { Data[rowA].goods_seq = stoi(token); cout << Data[rowA].goods_seq << endl;}
            else if (colA = 2) { Data[rowA].goods_unit_price = stoi(token); cout << Data[rowA].goods_unit_price << endl;}
            else if (colA = 3) { Data[rowA].ea = stoi(token); cout << Data[rowA].ea << endl;}
            else if (colA = 4) { Data[rowA].want_date = token; cout << Data[rowA].want_date <<endl;}
            else if (colA = 5) { Data[rowA].member_seq = stoi(token); cout << Data[rowA].member_seq << endl;}
            else if (colA = 6) { Data[rowA].shipping_cellphone = token; cout << Data[rowA].shipping_cellphone << endl;}
            colA++;
        }
        rowA++;
    }
}

为了解决您需要做==的问题,这发生在if (colA = 0)上,该问题应为if (colA == 0)

希望这有帮助