Hi, will be very grateful if anyone can help me out with this, cant seem to figure out how to do it, pretty new to c++, have done the basics up to structures + file reading so far at college, starting classes + pointers soon..anyway..
i need to change the bit thats in bold (which currently initialises values of student reg. numbers + marks(only marks[0] at the moment) and instead of this, read in the data from a file in the form where each line of the file contains:
ID Mark1 Mark2 Mark3 Mark4
[see end]
-currently weve done ifstream/ofstream things, such as ifstream myfile("Test.txt"); and myfile>>PIN[counter]; but nothing on how to read data into a struct
Very grateful for any help whatsoever, [ignore the Gwin. commands, its a library we use at college]
Thanks in advance
// Session8X_4.cpp :File reading into Structures
#include "stdafx.h"
#include "gwin.h"
#include <iostream>
using namespace std;
const int NMax =10;
const int NModules =4;
struct Pupil
{
int Registration;
double Marks[NModules];
}; //NOTE the final semi-colon
I can see where your coming from, but i think the problem is because there are different 'types' in the struct, such as int Reg, and Marks[Arrayof4] ..and the text file where i am reading from contains all the info in 1 [ separated by spaces]...so how would i go about reading each 'type' into whichever ever 'type' it belongs to in the stuct
for (int i = 0; i < Nmax, ++i) {
in_file >> TheClass[i].Registration; // put first into Registration;
for (int j = 0; j < 4; ++j)
in_file >> TheClass[i].Marks[j]; // put the rest into marks of the correct index;
}