I am using a library and it has a function:
static void printSingleExpr(std::ostream &os, const ref<Expr> &e);
However, I want to output to a file using ofstream rather than the std::ostream and when I pass an ofstream instance (as kind of expected) I am getting an error. Is there any way to achieve this without modifying the function itself (or overloading the function) ?
You must be passing it something wrong.
std::ofstreaminherits from, and can thus be used in place of,std::ostream. In other words, the following should work:Make sure your
std::ofstreamreference isn’t constant or volatile for some reason.