Created
November 18, 2019 17:43
-
-
Save avasyukov/6d9add8968feaf7d75dfc1e493b573e4 to your computer and use it in GitHub Desktop.
Sample of custom C++ stream processing with custom destination if necessary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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