getline??? how do I use something like it for an integer
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;
}
Those commented out getlines won't work because the struct type is wrong.
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.