Skip to content

Instantly share code, notes, and snippets.

@avasyukov
Created November 18, 2019 17:43
Show Gist options
  • Save avasyukov/6d9add8968feaf7d75dfc1e493b573e4 to your computer and use it in GitHub Desktop.
Save avasyukov/6d9add8968feaf7d75dfc1e493b573e4 to your computer and use it in GitHub Desktop.
Sample of custom C++ stream processing with custom destination if necessary
#include<iostream>
#include<sstream>
class CustomBuf : public std::stringbuf
{
public:
virtual int sync() {
// do whatever you want with this->str() here
std::cout << "Syncing stream: " << this->str() << std::endl;
}
};
int main()
{
CustomBuf cb;
std::ostream stream(&cb);
stream << "Hello custom stream processing with custom destination" << std::flush;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment