this is some of my code, could you work out how i am suppose to do this?
/*from main.cpp*/
Code:
student.read(cin);
student.print(cout) << endl;
/*from student.h*/
Code:
class Student {
public:
const char * getStudentID() const;
const char * getStudentName() const;
const char * getStudents() const;
ostream& print(ostream& stream) const;
istream& read(istream& stream) const;
private:
string StudentName;
int StudentID;
}
/*from student.cpp*/
Code:
const char * Student::getStudents() const{
string tmp;
tmp = getStudentName();
tmp += ": ";
tmp += getStudentID();
return (const char *) tmp.c_str();
}
ostream& Student::print(ostream& stream = cout) const {
stream << getStudents() << endl;
return stream;
}
istream& Student::read(istream& stream) const {
/*What goes here? any help?
getline(stream, name); //student name
getline(stream, id); //student id
want to do..
StudentName = name;
StudentID = id;
but this wont work..
*/
return stream;
}
---------------------------------------------------
im not sure how to write the read function. Could anyone give me a hand?
I would like the read function to read in the student's details (the Student's Name, and ID) and then call the function getStudents();
The main problem im having is to do with the const. It wont let me set the variables i wish to set.
thanks