void initializeVectorFromFile(vector<SInventory> & inven){
ifstream initData("inventoryData.txt");
if(!initData){
cout << "File could not be accessed! Press any key to terminate program...";
_getch();
exit(1);
}
while(!initData.eof()){
SInventory item;
initData >> item.itemID;
getline(initData,item.itemName);
initData >> item.pOrdered
>> item.menufPrice
>> item.sellingPrice;
item.pInStore = item.pOrdered;
item.pSold = 0;
inven.push_back(item);
cout << item.itemID << endl;
}
cout << "File Read Success!" << endl;
initData.close();
}
The .txt
file I am reading from contain data structured in this order:
int
string
int double double
The output which is in the last line of the while-loop is repeated as the first itemID within the file. The initData
stream does not read subsequent entries in the .txt
file.
1111
1111
1111
1111
1111
...