You can't "pass" the ostream to fprintf. The FILE
structure is platform dependent.
This is probably not the best way, but you can however create an evil macro:
#undef fprintf
#define fprintf my_fprintf
And you can create two my_fprintfs, one that takes FILE*
, and another that takes std::stringstream&
as argument.
You can avoid the macro by simply calling my_fprintf directly, but you have to modify the call site.
You can't "wrap stringstream in FILE*" portably, but there are some system specific ways. If that's what you after, then Linux for example has fopencookie() which take function pointers to read/write functions. You could then create functions that wrap std::stringstream.