Im tasked with reading a data file, this is an example snippet
list of trophy winners
year facup leaguecup 1stdiv 2ndiv
1960/61 Tottenham Hotspur Aston Villa Tottenham Hotspur Ipswich Town
1961/62 Tottenham Hotspur Norwich City Ipswich Town Liverpool
1962/63 Manchester Utd Birmingham City Everton Stoke City
The file starts in 1892 and is up to 2011/12, there is data missing for some years due to the wars etc,
once ive read the file, i need to store the data, for me to re-use.
Some guidance, where to start would be great, theres a lot of useful link regarding reading data in, but they tend to be with very small files with say 10 lines of numbers.
struct Winners
{
int year;
std::string fa_cup;
std::string league_cup;
std::string first_div;
std::string second_div;
};
int main()
{
std::vector<Winners> the_winners;
std::ifstream myfile ("trophywinners.txt");
while (getline(myfile, line))
{
// put the line in a string stream
std::istringstream buffer(line);
// read it back
std::string year, fa, league, first, second;
buffer >> year >> fa >> league >> first >> second;
// add a new item to the vector
the_winners.push_back(Winners());
// fill in the item just added
the_winner.back().year = convert_year(year);
the_winner.back().fa_cup = fa;
the_winner.back().league_cup = league;
the_winner.back().first_div = first;
the_winner.back().second_div = second;
}