Hey guys,
i am a beginner in c++ and i don't know what's wrong with my code. i'dont get any errors, but when i run the programme the following:
"...
Line: 251
Expression: vector iterators incompatible
..."
I think there is a problem with "b.getmark()" and "b.getcoursename()" but i don't know how to solve it since i cannot use "coursename" or "mark" instead
Thanks in advance, guys. I hope someone can help me!
My code looks a little bit strange cos some parts are not displayed properly... strangely the problematic parts.
Sorry about that.
This is my code:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class physics {
friend ostream & operator<<(ostream &os, physics &b);
private:
string studentname;
int studentid;
vector<string> coursename;
vector<double> mark;
public:
//access functions
string getstudentname(){return studentname;}
int getstudentid(){return studentid;}
vector<string> getcoursename(){return coursename;}
vector<double> getmark(){return mark;}
void enter(){
studentname = "John";
studentid = 12345;
coursename.push_back("astro");
coursename.push_back("qm");
mark.push_back(60);
mark.push_back(71);
}
}; // END of CLASS physics
//output stream
ostream & operator<<(ostream &os, physics &b){
os<<"Student name: "<<b.getstudentname()<<" "<<"Student ID: "<<b.getstudentid()<<" "<<endl;
vector<string>::iterator courseit;
vector<double>::iterator markit;
for(markit=b.getmark().begin(), courseit=b.getcoursename().begin();markit<b.getmark().end();++markit,++courseit){
os<<" "<<courseit&amp;lt;&amp;lt;" "&amp;lt;&amp;lt;markit<<endl;
}
return os;
} // end of ostream
// Main Programme
int main()
{
physics ph;
ph.enter();
cout<<ph<<endl;
return 0;
} // END OF MAIN