mardi 21 août 2018

Iterate through a vector of objects and find a variable that matches one pulled from a text file

So I have a vector of objects

vector<Module*> moduleVector;         

and i need to iterate through it and compare an attribute from the object to another attribute I'm pulling from a text file

I'm using an ifstream and getLine() to store the element that needs to be compared to the object's attribute (fileD is the opened file, markModId is the string variable)

getline(fileD, markModId, ' ');

But I am unsure of how I can refer to the object's attributes in an iterator. So my question is,

how do I compare the attribute from the file to the object using an iterator?

For reference here is my object constructor (id is the attribute I want to compare)

Module::Module(string id, string title, string lecturer, int 
courseworkWeight)
{
   code = id;
   name = title;
   lect = lecturer;
   cwWeight = courseworkWeight;
   exMark = 0; //ex mark initialised as 0
   /*
   Map to store coursework marks
   */
   map<string, float> CWmarks;
   //cwMarks.clear(); //cw marks map cleared

   //create a map that stores
}

And exMark is the attribute that needs to be added to the object.

Aucun commentaire:

Enregistrer un commentaire