Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Problem with reading in a csv file

$
0
0
It gets stuck in a loop and only seems to read the whole first line into
.city. I've never read in data with csv so any help is appreciated!

void loadData ( List<FootballTeam>& data)
{
	FootballTeam team;

	ifstream inFile ( "NFL_Coaches.csv" );

	if ( !inFile )
	{
		cout << "The file could not be found! \n";
		exit(0);
	}

		getline (inFile, team.city); 
	
		cout << team.city << endl; //used to test if code is being read in correctly

inFile.ignore();
		getline ( inFile , team.teamName);
		
inFile.ignore();
		getline (inFile, team.coach);
		

	inFile >> team.yearsofExperience;


	while ( !inFile.eof() )
	{
		data.addMember ( team );

		getline (inFile, team.city); 
		inFile.ignore();

		cout << team.city << endl;

		getline ( inFile , team.teamName);
		inFile.ignore();
		
		getline (inFile, team.coach);
		inFile.ignore();

		inFile >> team.yearsofExperience;
	}



I've tried moving around the .ignores to see if it was that, but I'm still getting the same result

Viewing all articles
Browse latest Browse all 51036

Trending Articles