C++ ostream : no operator match << & expected initializer before '&' token -
thanks in advance help! program student registration program.
input via file , results out file. general idea learn c++, method overloading -including operators , fstream
's. i'll post code compiler points please let me know if want see other code.
when go build compiler error points header file method, outside of class inside #endif
. see below.
std::ostream & operator << ( std::ostream & os, const registration & r);
the implementation of file such:
std::ostream &operator <<( std::ostream & os, const registration & r ) { os << "student id: " << r.getstudentid() << "\n" << "semester: " << r.getsemester() << "\n \n"; for(unsigned = 0; < r.getcount(); i++) { os << "\tunit name : " << r.getname(i) << "\n" << "\tunit id : " << r.getid(i) << "\n" << "\tcredit points : " << r.getcredits(i) << "\n" << "\tstudent mark : " << r.getresult(i) << "\n" << "\tdate : " << r.getday(i) << " " << r.getmonth(i) << " " << r.getyear(i) << "\n\n"; } os << "total credits :" << r.getcredits() << "\n" << "number of units : " << r.getcount() << "\n" << "average mark : " << r.getaverage(); return os; }
and main()
int main() { ifstream infile( "rinput.txt" ); if( !infile ) return -1; registration r; infile >> r; ofstream ofile( "routput.txt" ); ofile << r; // error here re- no match 'operator<<' cout << "\ncomputation completed. check output file. \n"; return 0; }
thanks again , help, hope isn't rookie error... it's late am.
edit: have "using namespace std" & #include in header files.
this code valid, except:
- need
#include <iostream>
- need either add
using namespace std;
or addstd::
beforeifstream
,ofstream
, ,cout
. - need overload
istream
registration
class.
edit: please add std::
rather using namespace std;
. mentioned completeness. :)
Comments
Post a Comment