CSV split data in C + + (CSV must be UTF-8)

Source: Internet
Author: User



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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.