Hello, so I am trying to create a small mini program that iterates through a vector and outputs something according to a book. I have no problem understanding the problem, but I came across a problem in which the iterator doesn't access the struct inside the vector. I can't seem to figure out why thought. Logically dereferencing the iterator should give me the struct, then accessing the fields inside the struct should be simple, "(*iter).FIELD". I could be wrong though...
This is the error
This is my codeCode:error C2039: 'name' : is not a member of 'std::vector<_Ty>'
This is my struct that I have located in another header file.Code:int main(){ typedef vector<Student_info> students; students studs; Student_info record; string::size_type maxlen = 0; while(read(cin, record)){ maxlen = max(maxlen, record.name.size()); studs.push_back(record); } sort(studs.begin(), studs.end(), compare); for(students::iterator i = studs.begin(); i != studs.end(); ++i){ cout << (*studs).name << string(maxlen + 1 - (*studs).name.size(), ' '); try{ double final_grade = grade(*studs); streamsize prec = cout.precision(); cout << setprecision(3) << final_grade << setprecision(prec); } catch(domain_error e){ cout << e.what(); } cout << endl } return 0; }
Code:typedef std::vector<double> homework; struct Student_info{ std::string name; double midterm, final; homework hw; };



LinkBack URL
About LinkBacks



