I desire to output the file contents to the console using file handling. The variable marks is user defined.Now the contents are saved in the file correctly(I have attached a screenshot below). When I want to read the file the user defined functions gives inaccuarte output for the last two times. Contents of file:
- Calculus 11
- FoP 22
- AP 33
- LCA 44
- Workshop 55
- Pak Studies 66
- English 77
Output
- Calculus 11
- FoP 22
- AP 33
- LCA 44
- Workshop 55
- Pak Studies 0
- English 1875928375
int marks[7],i=0;
string subject[7]={"Calculus","FoP","AP","LCA","Workshop","Pak Studies","English"};
ifstream file3("Task4.txt");
while(!file3.eof())
{
file3>>subject[i]>>marks[i];
cout<<subject[i]<<" "<<marks[i]<<"\n";
i++;
}
file3.close();