Re: modifying wcout by Doug
Doug
Mon May 28 21:49:54 CDT 2007
On Mon, 28 May 2007 18:52:13 -0500, DR <dr2222@yahoo.com> wrote:
>I wonder if it allowed to modify wcout. For example to write all wcout
>output to a buffer during a function call, how to do this?
>
>wchar *x;
>// setup wcout to write to buffer x
>my_function();
>// reset wcout
This should do it (wcout should be analogous):
#include <iostream>
#include <sstream>
int main()
{
std::cout << "console: Hello, world #1\n";
std::stringstream str;
std::streambuf* orig = std::cout.rdbuf(str.rdbuf());
std::cout << "str: Hello, world\n";
std::cout.rdbuf(orig);
std::cout << "console: Hello, world #2\n";
std::cout << str.rdbuf();
}
Output:
X>a
console: Hello, world #1
console: Hello, world #2
str: Hello, world
--
Doug Harrison
Visual C++ MVP