首页 > 解决方案 > 从向量读取时如何创建逗号分隔符?

问题描述

我有两个字符串向量readDatacommaSep. 我想从向量中读取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});
}

标签: c++

解决方案


推荐阅读