c++ - Creating String Array from CSV -


i have csv file of atomic elements atomic number, symbol, , name. file formatted as:

1,h,hydrogen
2,he,helium
3,li,lithium
...

i'd create array of symbols referenced atomic number. ie. arrayname[32]="ge";

i've been trying use sscanf hasn't been working. rough code below:

char temp[200]; float temp_z; std::string temp_ele; std::string temp_name;  while(!fin.eof()) { fin.getline(temp,200); sscanf(temp, "\"%f\",\"%s\", \"%s\"",&temp_z, &temp_ele, &temp_name);  cout<<temp_z<<endl; cout<<temp_ele<<endl; cout<<temp_name<<endl; } 

you can read each element so:

string thestrings[200]; //initialize correct size int = 0; string name; while(!fin.eof()) {     getline(thefilestream, name, ',' );     thestrings[i++] = name;     cout<<name<<endl; } 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -