Reading a input text file into a string

I have a text file in the format of the following:

1 25.00 hammer
2 300.00 chain saw
3 3.00 dust pan
4 20.00 wrench

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...
Thanks that set me on the right course. Here is what I did...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int ID = 0;
double price = 0.00;
string itemName = "empty";
char tempName[30];

inputFile >> ID >> price;
inputFile.getline(tempName, 30);

itemName = string(tempName);

while(!inputFile.eof())
{
  itemList.push_back(new Item(ID, price, itemName));

inputFile >> ID >> price;
inputFile.getline(tempName, 30);

itemName = string(tempName);
}
Topic archived. No new replies allowed.