Just a question

Hi all, im working on a little program that reads a list of basketball teams from a file and stores the data in a struct. Most of the teams only have one name and the data is stored in the struct perfectly. However, i am wondering what the best way to read in the data for teams that have a first AND a last name.
An example would be "1 Kansas 29-0 1" position, name, wins/losses, and previous position in the standings specifically. The program has a fit if the file looks like this however "3 Iowa State 10-19 -" the program NEEDS to read from a file that contains both of these lines.

Here is a sample of my read file code located in the class:
for (int i = 0; d != -1; i++)
{
d = inFile.peek();
inFile >> T[i].position >> T[i].name;
if (d > 49)
{
inFile >> c;
T[i].name += c;
}
inFile >> T[i].wins >> temp >> T[i].losses >> T[i].votes >> T[i].prev;
if (d == -1)
break;
Such lack of systematic format is inconvenient. CSV is an example of format(s) that make parsing easier.

However, you have "word-x word[s] word-y word-z" on a line. You could read every word into a container (or just std::string). Then you can look at the size of the container (or count whitespaces in string) to do something appropriate for each word.
thanks very much for the advice, ill try both and see which one works better for my particular program
Topic archived. No new replies allowed.