Those commented out getlines won't work because the struct type is wrong.Code:#include <fstream.h> //header for cout and cin #include <string.h> // header for strings #include <windows.h> // required for system("cls") struct chem { char symbol[2]; char name[25]; int numb; long mass; } main() { ifstream infile; int i = 0; char dummybuffer[25]; chem element[112]; infile.open("CHEM.DAT",ios::in); for (i=0; !infile.eof(); i++) { infile.getline(element[i].symbol, 256, ','||'\n'); //get data until new line infile.getline(element[i].name, 256, ','||'\n'); infile >> dummybuffer; element[i].numb = atoi(dummybuffer); infile >> dummybuffer; element[i].mass = atoi(dummybuffer); // infile.getline(element[i].numb, 256, ','||'\n'); // infile.getline(element[i].mass, 256, ','||'\n'); } infile.close(); cout << element[0].symbol; return 0; }
The non commented version would probably work, but I need it to stop as soon as it gets to a comma.
How might I do this?
Thanks.



LinkBack URL
About LinkBacks



