?
Solved

redirecting cerr

Posted on 1999-01-26
7
Medium Priority
?
288 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
Technology Partners: 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 120 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

Technology Partners: 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!

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

752 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