If you have the opportunity to change your library, you can use C ++ streams instead of C FILE streams.
If your old library function looked like this:
void SomeFun(int this, int that, FILE* logger) { ... other code ... fprintf(logger, "%d, %d\n", this, that); fputs("Warning Message!", logger); char c = '\n'; fputc(c, logger); }
you can replace this code:
void SomeFun(int this, int that, std::ostream& logger) { ... other code ... logger << this << ", " << that << "\n"; // or: logger << boost::format("%d %d\n") %this %that; logger << "Warning Message!"; char c = '\n'; logger.put(c); // or: logger << c; }
Then in your non-library code, do the following:
#include <sstream> std::stringstream logStream; SomeFun(42, 56, logStream); DisplayCStringOnGui(logStream.str().c_str());
Robα΅©
source share