我正在尝试从给定文件填充结构数组,但似乎什么也没读取。
/******************************************************************
* READ FILE
* This function opens the given file name and saves the info
* into an array.
******************************************************************/
int readFile(const std::string dataFile, AccessRecord accessRecordArray[], int &cou\
nt)
{
std::ifstream fin(dataFile.c_str());
if (fin.fail())
return -1;
std::string file;
while (!fin.eof())
{
fin >> file;
count++;
}
std::cout << count << std::endl;
for (int i = 0; i < count; i++)
{
fin >> accessRecordArray[i].fileName;
fin >> accessRecordArray[i].userName;
fin >> accessRecordArray[i].timeStamp;
}
fin.close();
return 0;
}
所有这些输出均为零,等于变量计数。你能帮我看看我在想什么吗?