I'm having trouble reading from file and saving the data into integer / double variables.
These are the contents of the file I have to read from.
& Student Roll Number, Student Name, CGPA
09i-0947, Peter Clark, 2.01
09i-01716, James Morrison, 2.02
10i-0024, William Craft, 2.09
& End
The code should ignore all lines starting with an & sign.
Then I have to save the starting 2 numbers in an integer variable called batch. The numbers after the "-" sign in an integer called rollnumber. Then the name and then the CGPA in a double variable. It should ignore the commas and the spaces. This is what I've come up with as yet but I don't know what to do next.
Code:
int x=0, y=0;
bool status;
ifstream fin;
fin.open("input.txt");
int i[100];
char getline[200];
char skip;
char batch[200][5], roll[200][6], name[200][30], cgpa[200][5];
char batcha[5], rolla[6], namea[30], cgpaa[5];
x=fin.tellg();
do
{
int count=0;
fin>>skip;
fin.seekg(x);
if(skip=='&')
{
fin.ignore(100, '\n');
status=false;
}
else
{
y=fin.tellg();
fin.getline(getline,200, '\n');
cout<<getline<<endl;
status = true;
}
x=fin.tellg();
if(status==true)
{
fin.seekg(y);
fin.getline(roll[count], 5, ',');
fin.getline(name[count], 30, ',');
fin.getline(cgpa[count], 5, '\n');
count++;
}
}
while(!fin.eof());
I have tried various other methods like string tokenizing etc but failed.
Regards.