Here is an example of the type of input I would be working with: (coming from standard input)
Archery,M,TEAM,Archery,Lord's Cricket Ground,1. GOLD,team ITA,Italy
Archery,M,TEAM,Archery,Lord's Cricket Ground,2. SILVER,team USA,United States
Archery,M,TEAM,Archery,Lord's Cricket Ground,3. BRONZE,team KOR,South Korea
Cycling,M,IND,Road,Regent's Park,1. GOLD,Aleksander Winokurow,Kazakhstan
Cycling,M,IND,Road,Regent's Park,2. SILVER,Rigoberto Uran,Colombia
Cycling,M,IND,Road,Regent's Park,3. BRONZE,Alexander Kristoff,Norway
Fencing,F,IND,Foil,ExCeL,1. GOLD,Elisa Di Francisca,Italy
InsertionEnd
As the title suggests I want to take each line, split it a the comma, and store each one of those strings into an array (or vector of strings). THEN I want to take each item in the array and use it as parameters for a function. I know how to read multiple lines and how to split a string but when I put those things together it's not really working out for me.
my line of thinking:
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
int main()
{
string line;
stringstream ss(line);
while (line != "InsertionEnd") {
vector<string> array;
getline(ss, line, ',');
array.push_back(line);
addItem(array[0],array[1],array[2],array[3],array[4],array[5],array[6],array[7])
}
}
so after I get my array i want to use an addItem function that I made which just creates an athlete structure (takes 8 parameters). like so:
myTable.addItem("Archery","M","TEAM","Archery","Lord's Cricket Ground","1. GOLD","team ITA","Italy");
Am I on the right track ? or is this completely off base?? thanks.
note: I have tested the addItem functions and it works when you just type in the parameters yourself.