파일에서 항목 목록을 읽은 다음 벡터에 저장하려고합니다. 문제는 내 코드가 벡터에 마지막 항목을 두 번 더하고 프로그램이 끝났음에도 불구하고 파일을 계속 읽는 이유가 확실하지 않다는 것입니다.파일에서 데이터 읽기 및 벡터에 저장
다음은 텍스트 파일의 내용입니다. 벡터의 내용을 표시하면 "오렌지"선이 두 번 나타납니다.
사과 파운드-10 2
오렌지 파운드 - 5 6
여기 // 이것은 전형적인 파일
while (!inputFile.fail())
{
//Extract the line from the list
getline(inputFile,item_name,'-');
getline(inputFile,item_unit,'-');
inputFile >> item_amount;
inputFile >> item_price;
//Create an instance of the item object
Item New_Item(item_name, item_unit, item_amount,item_price);
//Push it to the list vector
list.push_back(New_Item);
}
//Close the file
inputFile.close();