STD::stringSTRTMP;STD::stringSUBSTRTMP;STD::stringstr;intpos =0;intSUBPOS1 =0;intSubPos2 =0;D ata fileData= Fileutils::getinstance ()->getdatafromfile (Fileutils::getinstance ()->fullpathforfilename ("Data/selectcard.csv") ; Str.clear (); Str.assign ((Const Char*) filedata.getbytes (), filedata.getsize ());/*string disassembly for (int i = 0; i < data.getsize (); i++) {pos = Str.find ("\ n", i); strtmp = Str.substr (i, pos-i); I = pos;}*/ for(unsignedinti =0; I < str.size (); i++) {pos= Str.find ("\ n", i); Strtmp= Str.substr (i, POS-i); //split the data, the first line does not if(I! =0) {selectcarddata_s*data =Newselectcarddata_s; SUBPOS1=0; //SubPos2 = Strtmp.find (",", SUBPOS1); Substrtmp= Strtmp.substr (SUBPOS1, SubPos2-subPos1); Data->id =atoi (Substrtmp.c_str ()); SUBPOS1= SubPos2 +1;//need to self-add, skip the split symbol//SubPos2 = Strtmp.find (",", SUBPOS1); Substrtmp= Strtmp.substr (SUBPOS1, SubPos2-subPos1); Data->cardtype =atoi (Substrtmp.c_str ()); SUBPOS1= SubPos2 +1; //SubPos2 = Strtmp.find (",", SUBPOS1); Substrtmp= Strtmp.substr (SUBPOS1, SubPos2-subPos1); Data->rewardmultiple =atoi (Substrtmp.c_str ()); SUBPOS1= SubPos2 +1; //SubPos2 = Strtmp.find (",", SUBPOS1); Substrtmp= Strtmp.substr (SUBPOS1, SubPos2-subPos1); Data->chance =atof (Substrtmp.c_str ()); SUBPOS1= SubPos2 +1; //Record Datadatamap[Data->id] =data; } if(pos = =-1 ) { Break; } I=Pos;}
The data format for the split CSV is:
1,5,ten, test
So starting with the second line is the real data.
CSV split data in C + + (CSV must be UTF-8)