if (infile.is_open())
{
int count = 0;
while (infile)
{
string author, ratings;
getline(infile, author);
if (author != "")
{
getline(infile, ratings);
// TODO: Create new User object
User newuser(author, ratings);
// TODO: Add new User object to vector
userList.push_back(newuser);
count++;
}
}
cout << count << " users read in. Closing user file." << endl;
我得到的這個輸出是從文本文件中讀入86個用戶。正確的輸出應該是32.我認爲這是因爲我正在使用while循環,但我不完全確定。文件不正確添加
是什麼infile中的數據類型? ....如果你使用'Filestream infile',它是一些任意參考內存的十六進制數字(非常大的數字) – 2014-12-05 07:13:49
嘗試以二進制模式打開你的文件。 – 0x499602D2 2014-12-05 07:14:32
@AVIKDUTTA infile是一個整數列表 – BrandonTuley43 2014-12-05 07:14:46