C++ I need help with Arrays/files, please

my problem is i cant read the names from a file and into an array
the txt file is formatted like this,,o and i cant use 2d arrays

name place(exp 1st 2nd 3rd) score
exp: blake jacobs 40th 340
bob john 57th 424

so far i have this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 #include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
#define MAX 100
int main(){
ifstream inFile;
string name[MAX];
int place[MAX];
int score[MAX];
int number;
inFile.open("test.txt");
if (inFile.fail()) 
{
cout << "No such file"<< endl;
}

int count = 0;


while(!inFile.eof()&& count <MAX)
{
getline(inFile,name[count]);
inFile >> place[count]>>score[count];
count++;

}
cout << name<<endl;
cout<< place;
Last edited on
getline() reads a whole line, including the position and score.
Position is not an integer.

If every name has one word for forename and one word for surname, then reading two words and concatenating them would work. If, however, Reginald van der False Sr attends the race, then the simple routine will fail.

Plan B:
1. Read the whole line.
2. Find the last word from the line and store it into score.
3. Find the second to last word from line and store to position.
4. Store the rest of the line as name.
Topic archived. No new replies allowed.