| re: Help on istream& operator ?
tvn007 wrote:[color=blue]
> Please help why this code not compile[/color]
Well, the compiler told you, in the error message. Please post it,
there are good reasons why the FAQ says you must do that.
[color=blue]
> ///////////////////////////////////////////////////////////////////////////////////////////////////////
> #include <iostream>
> #include <string>
> #include <fstream>
> #include <sstream>
> using namespace std;
> const int MAX=50;
> struct Record_info {
> string bypassed;
> string name;
> int midterm;
> double quiz;
> double final;
> string testname;
> }student[MAX],*ptrstudent;
>
> int main (void){
> ptrstudent = student;
> ifstream in ("test2.txt");
> string line;
> string line2;
> char buffer[40];
> while (getline(in,line)){
> if (line.find("#")!=string::npos)continue ;
> istream& operator >>(istream & is,prtstudent & r){
> is>>r.bypassed>>r.name>>r.midterm,r.quiz,r.final,r .testname;}
> ptrstudent++;
> }
> return 0;
> }[/color]
Functions should be defined and used separately. It looks like you
don't
understand the difference, and you tried to put something that's
neither
a definition nor a call of operator>> inside main.
Try a simpler program first, defining and calling a function void
print_hello_world( )
HTH,
Michiel Salters |