逗号分隔的字符串流错误。它还分隔“-”

comma separated stringstream error. it also separates '-'

以下是一组数据,我想将其保存在数组中,使用 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

我使用了以下帮助来做到这一点。 How to use stringstream to separate comma separated strings 但是我遇到了两个问题。日期保存为:

2017

和phone号码保存为:

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)

希望对您有所帮助