我的.CSV文件看起来像这样
不能跳
中等
错误
每次进入厄运之洞,我都无法跳跃。
马太贵了中等
改进
马匹花费太多黄金,请降低成本。
我正在将每四行读入矢量下标。我希望它继续读四行,直到它到达文件的末尾。
这是我的循环:
int i = 0;
while (bugDB.good())
{
bugList.push_back(bug());
getline(bugDB, bugList[i].title, '\n');
getline(bugDB, bugList[i].importance, '\n');
getline(bugDB, bugList[i].type, '\n');
getline(bugDB, bugList[i].description, '\n');
i++;
}
由于某种原因,它在第一次循环后停止读取.CSV文件,因此我的程序只能看到
不能跳
中等
错误
每次进入厄运之洞,我都无法跳跃。
其他一切都未被记录。我认为它可能是.CSV格式,但我在.txt中尝试过它仍然不起作用。感谢您的任何帮助。
编辑:对于通过搜索找到此内容的任何人,我已经找到了如何处理以这种方式设置的文本文件。
int i = 0;
while (bugDB)
{
bugList.push_back(bug());
getline(bugDB, bugList[i].title, '\n');
getline(bugDB, bugList[i].importance, '\n');
getline(bugDB, bugList[i].type, '\n');
getline(bugDB, bugList[i].description, '\n');
i++;
}
我改变的是条件(bugDB.good())到(bugDB)。您还需要在文件末尾写一个新行。