【发布时间】:2015-08-07 11:05:11
【问题描述】:
我正在尝试将文本文件中的一些记录加载到动态数组中。
记录用逗号分隔
eg: lost,cat,female,persian,0 3,black
这是我目前所拥有的:
struct Pet{
char status[6];
char petType[4];
...
}
void loadRecords(char * filename, Pet * petPointer, int count){
ifstream fin;
Pet* petPointer = new Pet[count];
fin.open(filename);
for (int i = 0; i < count; i++)
{
while (fin.good())
{
getline(fin, petPointer->status[i], ',');
...
}
}
}
这将返回错误“没有重载函数“getline”的实例与参数列表匹配”
将这些记录加载到数组中的最佳方法是什么?
【问题讨论】:
-
使用
#include <iostream>并以std::为前缀。
标签: c++ arrays dynamic getline