Advertisement

08.23.2007 at 01:34PM PDT, ID: 22783539 | Points: 500
[x]
Attachment Details

How do I intercept and redirect std cout and cerr output? (I need the string, I wont be printing to a file)

Asked by thegilb in C++ Programming Language

Tags: ,

I'm working on a piece of code that is intended to capture standard cout and cerr streams and redirect the output to anywhere I want. So what I want to do is to be able to write something like:
cout << "anything" << endl;

Then I want to be able to get the string which would normally be output to - wherever it normally goes. Like in a console application the standard output would normally be printed to the console window. I need access to the string so I can put it elsewhere.

So I've started out with my references on rdbuf which I am assured allow me to install my own streambuf object. No problem, I've written the beginning of a class which inherits from stringbuf. Now I'm just a little bit stuck because I dont know what to override to intercept the usual code flow and achieve my goal of obtaining that string.

So far I've tried overriding sputc and sputn but that hasn't worked. This is one of those esoteric C++ features that it seems to be quite hard to find much in the way of references which is why I come here. In case it makes a difference I'm working with C++ in VS2005.

All comments appreciated, but the points will go to anyone who can provide me with the information I need to write a working solution. Thanks for reading!Start Free Trial
 
Loading Advertisement...
 
[+][-]08.23.2007 at 01:39PM PDT, ID: 19757608

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.23.2007 at 01:50PM PDT, ID: 19757677

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.23.2007 at 03:25PM PDT, ID: 19758346

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.24.2007 at 12:19AM PDT, ID: 19760282

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.24.2007 at 02:13AM PDT, ID: 19760663

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.24.2007 at 02:37AM PDT, ID: 19760743

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.24.2007 at 03:07AM PDT, ID: 19760863

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.24.2007 at 06:46AM PDT, ID: 19762082

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.24.2007 at 05:59PM PDT, ID: 19766422

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.25.2007 at 12:21AM PDT, ID: 19767078

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.30.2007 at 03:52AM PDT, ID: 19798833

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-44 / EE_QW_1_20070628