-2
類
的情況下這是在我的文本文件中的一行是這樣的:信息和分配各行
1 1 10 20 20 50 donut frank 0.75 1.50 100.00
每個單獨的類變量用空格分隔。我的代碼永遠不會讓它進入while循環。有人可以解釋發生了什麼以及我如何解決它?
void load_inventory(vector<Item*> &items, string filename){
ifstream infile;
infile.open(filename.c_str());
istringstream stin;
string line;
cout << "WORKS" << endl;
if(!infile){
cout << "there was an error opening the file" << endl;
return;
}
while(!infile.eof()){
cout << "INSIDE THE LOOP" << endl;
Item* item = new Item();
getline(infile, line);
stin.str(line);
item->setMonth(stin);
item->setId(stin);
item->setNum(stin);
item->setDesired(stin);
item->setLife(stin);
item->setVolume(stin);
item->setName(stin);
item->setSupplier(stin);
item->setCost(stin);
item->setPrice(stin);
item->setSales(stin);
items.push_back(item);
stin.clear();
stin.seekg(0);
}
}
它停在哪裏?你嘗試過調試嗎? – crashmstr
文件名是否指向有效的文件?如果它是相對的,則需要根據執行程序的目錄提供。 – Attila
您的代碼(特別是Item類)需要重新設計。 – 0x499602D2