Now my confusion comes because I need the item name to be one string. My loop reads in the int, double, and string fine for the first item. The second item however causes chaos. The items that have a name longer than 1 word give me trouble. Can someone please explain to me how I can get the full item name when they are separated by a space within the text file and turn it into a single string. I've searched, but I can't find a clear answer.
1 2 3 4 5 6 7 8 9 10 11 12
int ID = 0;
double price = 0.00;
string itemName = "empty";
inputFile >> ID >> price >> itemName;
while(!inputFile.eof())
{
itemList.push_back(new Item(ID, price, itemName));
inputFile >> ID >> price >> itemName;
}
There will of course be several ways
1. read the entire line and seperate out the values
2. check the size of the line and make sure you got it all
3. what I like about this one is that the first number is a sequential number.
I would recommend keep reading until the input is the next number in order, just in case the name had more than 2 such as little pink hammer...