infinite loop = infinite frustration!! Help --> c++

piski

Senior member
Jan 21, 2002
312
0
0
I need to design a program in visual c++ that reads in from a file and prints out what it reads in. the way the data is set up on the file is

product code (space) quantity (space) item description.

The problem is sometimes the item description is 2 words and sometimes it is one..

ex. coffee table as opposed to chair. . How can i set that last variable to take in both words? i think this is the reason that i keep getting the old infinite Loop

thanks

K
 
 

PrincessGuard

Golden Member
Feb 5, 2001
1,435
0
0
One way is to read in one line at a time (e.g. using getline()) and parse it word by word with a tokenizer, stringstream, or similar. You know that after the 2nd word you're dealing with the description so just loop through the words and append to your string variable.
 

Vadatajs

Diamond Member
Aug 28, 2001
3,475
0
0
Originally posted by: PrincessGuard
One way is to read in one line at a time (e.g. using getline()) and parse it word by word with a tokenizer, stringstream, or similar. You know that after the 2nd word you're dealing with the description so just loop through the words and append to your string variable.

In keeping with this suggestion, I would add that you use a different character (other than space) to separate the tokens.
 

UlricT

Golden Member
Jul 21, 2002
1,966
0
0
are you creating the file? if so, you could also use rudimentary tags for each part, getline() the whole line, and split up the resulting string to get each value.
 

sandorski

No Lifer
Oct 10, 1999
70,697
6,257
126
Originally posted by: Vadatajs
Originally posted by: PrincessGuard
One way is to read in one line at a time (e.g. using getline()) and parse it word by word with a tokenizer, stringstream, or similar. You know that after the 2nd word you're dealing with the description so just loop through the words and append to your string variable.

In keeping with this suggestion, I would add that you use a different character (other than space) to separate the tokens.

Yup, as Yakuza stated, insert a "_" or some other character on the Input side, then on the Output side remove the "_" and replace it with a space.