I am trying to enter some soccer player data into an array of soccerplayers (a structure)
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct sPlayer{
char lname[20];
char fname[20];
int birthmonth;
int birthday;
int birthyear;
};
int main() {
sPlayer players[10] = {};
string input;
string foo;
ifstream inputFile;
inputFile.open("players.txt");
//check for error
if (inputFile.fail()){
cerr << "error opening file" << endl;
exit(1);
}
int count = 0;
while (!inputFile.eof()){
getline(inputFile, input, ' ');
players[count].lname = input;
count++;
}
inputFile.close();
cout << input;
cout << "\n2–display original data, 3–sort data , 4–display sorted data 5–search by lastname 6–exit the program\n";
}
players.txt file:
Roberto Baggio 01 12 1992
David Beckham 05 12 1988
Pablo Aimar 05 13 1987
Michael Ballack 11 13 1999
Gabriel Batistuta 05 05 1979
Franz Beckenbauer 18 01 1976
Dennis Bergcamp 03 14 1989
Omar Bravo 03 03 1999
Jared Borgetti 09 23 1977
Fabio Cannavaro 02 25 1991
I get an error because I can't assign players[count].lname
to input, but I don't know how to match up my data types. I am reading in 2 char arrays for fname and lname, 3 ints for birthday/month/year.