c++ - 从向量读取时如何创建逗号分隔符?
问题描述
我有两个字符串向量readData
和commaSep
. 我想从向量中读取readData
数据,每当遇到逗号 (,) 时,我都想将该数据插入commaSep
不带逗号的位置。在我的程序readData
中有像“ xyz,22,pqr
”这样的值。我的 getline 声明是错误的,所以给我一些建议。
vector<string> readData; // has string values with ',' separation
vector<string> commaSep; // insert them in this vector
string temp;
for (int i = 0; i < readData.size(); i++) {
getline(readData[i], temp, ',');
commaSep.push_back({temp});
getline(readData[i], temp, ',');
commaSep.push_back({temp});
getline(readData[i], temp, '\n');
commaSep.push_back({temp});
}
解决方案
推荐阅读
- kotlin - 如何使用 Jackson Object Mapper 将 UUID 值从 Json 映射到 Java 对象?
- javascript - 与 js“.sass 文件”共享 sass 变量
- java - 杰克逊在使用 JsonTypeInfo.As.WRAPPER_OBJECT 时排除特定类的包装
- javascript - 如何为具有必须匹配特定键和来自另一个数组的相同值的值的数组执行 foreach
- php - 将数组数据的字节转换为pdf下载?
- django - 如何根据 django 模型中字段的比较值进行过滤?
- scala - 在scala中处理无效参数的最佳方法是什么
- angular - 如何使用 ng-select 更改事件到达元素
- c - 是否可以以编程方式设置当前的 Linux 运行级别?
- php - 如何使用rest api在amazon中使用asin no获取产品详细信息?