I'm trying to read data from a csv file into a vector of structs each containing various values from a football game (offensive team, quarter, down, yards to go, play desc, etc). I'm trying to use stringstream to convert strings to ints but i'm returning junk data.
Data d; //structs
vector<Data> TeamData; //vector of structs
string s;
istringstream iss( s );
ifstream myfile;
myfile.open("CSV file here"); //open CSV file
while ( !myfile.eof() )
{
getline (myfile, d.gameid, ','); //read to comma, store in d.gameid
getline (myfile, s, ','); //read to comma
iss >> d.qtr; //use stringstream to store into d.qtr
repeat for remaining values . . .
The cvs file looks similar to this if you're wondering:
20070906_NO@IND,1,47,25,IND,NO,1,10,31,(2:25) J.Addai up the middle to NO 27 for 4 yards (S.Fujita).,0,0,2007
20070906_NO@IND,1,46,42,IND,NO,2,6,27,(1:42) P.Manning pass deep left to M.Harrison for 27 yards TOUCHDOWN.,0,0,2007
My program returns data like this when i try to output everything of relevance:
Game ID: 20070906_NO@IND
Offensive team: IND
Quarter: 7077994
Down: 4696320
To go: 4670480
Play: (2:25) J.Addai up the middle to NO 27 for 4 yards (S.Fujita).
Game ID: 20070906_NO@IND
Offensive team: IND
Quarter: 7077994
Down: 4696320
To go: 4670480
Play: (1:42) P.Manning pass deep left to M.Harrison for 27 yards TOUCHDOWN.