【发布时间】:2018-05-13 20:21:29
【问题描述】:
以下是我要保存在数组中的一组数据,使用 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
电话号码保存为:
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++;
}
}
【问题讨论】:
-
使用
==进行比较 -
使用
-Wall编译会提醒您可能出现此类问题。 -
你能说得更具体一点吗==
-
天哪...当然应该是 ==.!!非常感谢!!
标签: c++ tokenize stringstream