What I want:
From string: 24.5,0, 9, 8,FLB
Get Time : 24.5
CAN_ID: 0
RCTBSTAT: 9
R_L: 8
RCTBSTAT_Convert: FLB
getline()
and strtok()
could not meet what I need.
I read a csv file with the function getline()
and it work perfectly fine.
However, it troubles me when I wanted to split the string acquired which is in the form of: 0.00222,0,FALSE,345vdd,FALSE,...
and assign it to different variables.
Could you suggest any alternatives?
struct data
{
double Time;
int CAN_ID;
int RCTBSTAT;
int R_L;
unsigned char RCTBSTAT_Convert;
unsigned char R_L_Convert;
int TRD_ID;
bool ALRT;
bool NEW;
bool EXTRAPOL;
bool GHST_POS;
int X_WDTH;
int RCS;
int REL_X;
int REC_Y;
int REL_VX;
int REL_VY;
int X_WDTH_Convert;
float REL_X_Convert;
float REL_Y_Convert;
double REL_VX_Convert;
double REL_VY_Convert;
};
int main(int argc, char *argv[])
{
ifstream inFile(argv[1]);
string line;
string headline;
string rowitems;
int linenum=0 ;
getline (inFile, headline, '\n');
for (linenum=1; getline (inFile, line); linenum++)
{
//cout << "\nLine #" << linenum << ":" << endl;
istringstream linestream(line);
istringstream headerstream(headline);
********
**help**
********
}
return 0;
}