Created
May 10, 2014 12:08
-
-
Save atcruice/8a3b0ab197bd5931a48c to your computer and use it in GitHub Desktop.
C++ stream redirection for testing
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
// save current buffer | |
streambuf* coutBak = cout.rdbuf(); | |
// setup temp stream | |
stringstream coutBuf; | |
// redirect to temp | |
cout.rdbuf(coutBuf.rdbuf()); | |
// test against contents of coutBuf.str() | |
// reset | |
coutBuf.str(""); | |
// test again | |
// restore stream | |
cout.rdbuf(coutBak); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment