逗号分隔的字符串流错误。它还将'-'分开
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
我使用以下帮助来做到这一点。如何使用弦乐分开逗号分隔字符串但是我遇到了两个问题。日期保存为:
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)
希望这有帮助
相关文章:
- 如何将 txt 文件中的行分隔为组件C++
- 无法通过空白将文本文件行分隔为矢量
- 如何在C++中读取空格分隔的输入 当我们不知道输入的数量时
- 如何将以逗号和空格分隔的整数读取到 2D 数组中?
- 绑定派生类方法C++从实例范围之外的分隔 std::function 变量调用
- 在C++的两个字符串中连接以逗号分隔的唯一值
- 如何逐行读取文件,每行中的内容都用空格分隔并将其写入新文件中
- 用于存储由空格分隔的字符串的 C++/C 数据结构
- C ++中的StringStream有助于使用向量从字符串中提取逗号分隔的整数,而不是空格分隔的整数,为什么?
- 如何在 C++ 中将文件中的逗号分隔数字读取到数组中?
- "Warning: Comma within array index expression"但逗号分隔函数参数
- C++逗号分隔的输入数组代码过早退出
- 如何分隔字符串并将标记传递给方法
- 分隔整数 (C++) 的数字
- 野牛/yacc 解析器在不被空格分隔时跳过 grammer - "unexpected $end"
- 读取制表符分隔的文件时出现问题 C++
- 通过分隔符分隔包含 UTF-16 BE 文本的uint8_t数组
- 逗号在重载 ostream 和 istream 在结构中分开
- 如何更新和删除文本文件中的特定逗号分隔值?C++
- 逗号分隔的字符串流错误。它还将'-'分开