dimanche 29 mars 2015

Using and if/else statement to output to screen or file

I am making a program for a class and have a virtual output function and an iterator that either outputs to screen with certain logic or outputs to file with certain logic. The problem I am running into is that it calls the IF part in the case where it should be calling the else. Wondering if someone could shed some light on this.


calling the Output function with :



ofstream fout;
fout.open("save.txt");
if (!fout.fail()){
for (list<pethousedotcom*>::iterator it = homelist.begin(); it != homelist.end(); it++)
(*it)->output(fout); //<-- calling function below still calling the one that is only supposed to be for cout


Output function:



void bird::output(ostream& os) const {
if (os == cout) {
//still being executed
}
else {
// being skipped
}
}


Anything obvious wrong here? or any advice?


Aucun commentaire:

Enregistrer un commentaire