Solved

redirecting cerr

Posted on 1999-01-26
7
285 Views
Last Modified: 2010-04-16
How do I redirect cerr to a string var instead of printing to the screen????
0
Comment
Question by:meetze
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 1

Expert Comment

by:newexpert
ID: 1185147
You don't redirect cerr.  You create a strstream that's associated with a char* buffer or a stringstream associated with a c++ string.

eg
char buf[256];
strstream mystream(buf);
mystream << "Your output";

0
 

Author Comment

by:meetze
ID: 1185148
but i want to redirect the errors messages from the screen to a variable....
0
 
LVL 22

Expert Comment

by:nietod
ID: 1185149
I believe--I'm not sure this is allowed--you can use the init() procedure to specify a new stream buffer for a stream.  With this you can make cerr use a basic_stringbuf that you declare.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:meetze
ID: 1185150
if you could give me and example of how to rredirect it i would accept your answer....
0
 
LVL 22

Accepted Solution

by:
nietod earned 30 total points
ID: 1185151
For 20pts, you don't get too much....

A little more reasearch shows that the rdbuf() function can be used for this  

Try something like

// at start of main.
basic_streambuf<char> NewBuf;
basic_streambuf<char> *OldBufPtr = cerr.rdbuf(&NewBuf);

//cerr now uses  NewBuf.

// At end of main.
cerr.rdbuf(OldBufPtr);
// cerr now uses its original stream buffer.  


0
 

Author Comment

by:meetze
ID: 1185152
i am running low on points....thanks
0
 
LVL 22

Expert Comment

by:nietod
ID: 1185153
That's okay.  Its just that for 20pts, I don't like to start doing research and testing in an area I'm not famialr with.  I just answered because it looked like it wasn't going to get any more help and I thought it was better than nothing.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
thread-safe code in c++ 2 126
max float value 3 68
How to Correctly derive class from CWinThread in MFC 4 112
cmake and message 1 18
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question