【发布时间】:2021-02-23 08:43:31
【问题描述】:
我阅读的真实文件大约是 15.000 kBs。因此我不确定这是否是存储这种数据结构的最佳方式。
这里是代码。
string line;
ifstream File;
vector<vector<string>> v;
string filename = "meddra.txt";
File.open(filename);
if (File.is_open()) {
while (getline(File, line)) {
stringstream ss(line);
vector<string> row;
while (getline(ss, line, ',')) {
row.push_back(line);
}
v.push_back(row);
}
}
这里是示例文本文件:
CID100000085,CID000010917,C0000729,腹部绞痛 CID100000085,CID000010917,C0000737,腹痛 CID100000085,CID000010917,C0002418,弱视 CID100000085,CID000010917,C0002871,贫血 CID100000085,CID000010917,C0003123,厌食症
感谢您的贡献。
【问题讨论】:
-
当
v的类型为vector<vector<string>>,那么v[c]的类型为vector<string>。因此v[c][j]的类型为string。 -
你忘记
push_back到v
标签: c++ file vector ifstream push-back