Solved

redirecting cerr

Posted on 1999-01-26
7
280 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
  • 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now