Hi i have a task to stores marks for students, a struct is used to store this.
the thing giving me trouble at the moment is how to read and store a floating point number within a struct, the data specifically for the mark is on 1 line of a text file seperated by white space.
I cant seem to find a way to copy floating point numbers from a stream object, appreciate any response.
what i have so far, stores the first record minus the marks fine, anything after that, as i cant figure out how to store the marks doesnt work.
#include <iostream>
#include <fstream>
#include "ass1.h" // to link functions to a main file containing only a text based menu.
using namespace std;
const int MAX = 200;
int classSize;
int completedLabs;
struct StudentRec
{
char familyName[15];
char givenName[16];
char computerLogin[5];
float marks[12];
};
StudentRec student[MAX];
void ReadFile();
void ReadFile()
{
char filename[20];
cout << " Enter filename " ;
cin >> filename;
ifstream myfile(filename, ios::in);
if (myfile.good())
{
int numrecords = 0;
myfile >> classSize;
myfile >> completedLabs;
while (!myfile.eof())
{
myfile >> student[numrecords].givenName;
myfile >> student[numrecords].familyName;
myfile >> student[numrecords].computerLogin;
// myfile.read (student[numrecords].marks,12, '/n')
numrecords++;
}
myfile.close();
}
cout << classSize;
cout << completedLabs;
cout << student[0].givenName;
cout << student[0].familyName;
cout << student[0].computerLogin;
}
10 5
Dennis Iddis di504
1 1 -1 1 1
Alex Sywlrskbi as579
-1 -1 1 0.5 0
Terry Hdroribj th074
1 1 -1 -1 0.5
Glen Gowfz gg935
1 -1 1 1 0.5
Jake Qivghswcb jq137
-1 -1 1 0.5 1
Quan Jlrgxyl qj244
1 1 1 0.5 0.5
Vu Qcpwxwsf vq077
1 1 1 1 1
Glen Lqntw gl377
0 0 0 1 1
Terry Kowucgql tk422
1 1 1 1 0
Una Yeelkn uy473
0.5 0 1 1 1
Text File format.