473,396 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Redirecting cerr

Hi,
how can one redirect std::cerr into a file? Specifically, if I have an
ofstream object, is there something I can do to make "cerr << ..." calls
write into that particular ofstream object?

Thx,
Agoston
Jul 22 '05 #1
2 5992
Agoston Bejo wrote:
how can one redirect std::cerr into a file?
I have answered this question loads of times in the past: you can
replace 'std::cerr's stream buffer. However, since 'std::cerr' is
possibly accessed after exiting 'main()', you probably need to
restore the original stream buffer or allocate your stream buffer
on the heap.

Specifically, if I have an ofstream object, is there something I can do to make "cerr << ..." calls write into that particular ofstream object?


| std::ofstream out(...);
| std::streambuf orig = std::cerr.rdbuf(out.rdbuf());
| ... // use redirected cerr
| std::cerr.rdbuf(orig);
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting

Jul 22 '05 #2

"Agoston Bejo" <gu***@freemail.hu> wrote in message news:cr**********@news.caesar.elte.hu...
Hi,
how can one redirect std::cerr into a file? Specifically, if I have an
ofstream object, is there something I can do to make "cerr << ..." calls
write into that particular ofstream object?

Thx,
Agoston


Look at
* http://groups-beta.google.com/group/...4204134e9956a0
* http://alexvn.freeservers.com/s1/download.html (Redirecting cout/cerr <--> file )
--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn


Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Mike - EMAIL IGNORED | last post by:
I have a VC++6.0 program than calls library functions that write to cerr. I would like to capture this output in the calling program. Would you please let me know how I could to this? If I...
2
by: Trevor | last post by:
Hello, Please bear with me, I am trying to learn C++. I am implementing some error/debug functions which format a message and output it to a C++ stream. I would like to design it using one low...
9
by: Michael | last post by:
I've written my progrma to use cout a lot, but now i want to output this to a file instead of the screen. How do i do this Is it platform specific (if so then sorry) Thanks Mike
1
by: Gurikar | last post by:
How to redirect information to file usinf cerr or clog. Regards
8
by: Dylan | last post by:
What advantages does std::cerr offer over std::cout? (I'm trying to understand why it exists) thanks
8
by: sandwich_eater | last post by:
I get compiler error "cerr undeclared first use this function." #define err_ret(e) cerr << e; return -1 .... err_ret("who ate my muffy?");
2
by: Jason Heyes | last post by:
Here is what I use to redirect printed messages to a file: std::ofstream file("logfile"); std::cout.rdbuf(file.rdbuf()); std::cout << "this message goes to a file" << std::endl; Will the...
8
by: Morpheus | last post by:
I am trying to test a function that outputs text to the standard output, presumably using a cout call. I do not have access to the source, but need to test the output. Is this possible? I can...
1
by: Scott | last post by:
Hello, I am not entirely clear on the difference between cerr and clog. When it is more appropriate to use one versus the other? I am coding a simple C++ application that will issue error and...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.