Sunday, 15 September 2013

Convert text to csv file in C++? -



Convert text to csv file in C++? -

i got text file contain lots of line following:

data[0]: a=123 b=234 c=3456 d=4567 e=123.45 f=234.56

i trying extract number out in order convert csv file in order allow excel import , recognize it.

my logic is, find " " character, chop info out. example, chop between first " " , sec " ". viable? have been trying on did not succeed.

actually want create csv file like

a, b, c, d, e, f

123, 234, 3456 .... blablabla

234, 345, 4567 .... blablabla

but seems quite hard specific task. there utilities/better method help me this?

i suggest take @ boost::tokenizer, best approach have found. find several illustration on web. have @ high-score question.

steps: each line:

cut string in 2 parts using : character cut right part several strings using space character separate values using = character, , stuff these std::vector<std::string> put these values in file.

last part can like:

std::ofstream f( "myfile.csv" ); for( const auto& s: vstrings ) f << s << ','; f << "\n";

c++ csv

No comments:

Post a Comment