Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9166125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:05:10+00:00 2026-06-17T15:05:10+00:00

Is there a way to execute a callback function, or otherwise call a predefined

  • 0

Is there a way to execute a callback function, or otherwise call a predefined function whenever data is written to a standard stream such as stderr or stdout? Ideally, this could be used to allow an application to output as normal with printf in the case of stdout or fprintf for other FILE streams, and conditionally perform additional tasks such as assert dependent on current settings. This could have the benefit of automatically triggering this error handling code when other libraries output to the stream.

I know that output to stderr and stdout can be redirected to other FILE handles using std::freopen. Is it practical to implement an alternate FILE stream which provides this behavior, or would that require re-implementing a great deal of standard library functions?

Standards-compliant C++ suggestions (including C++11) would be preferred, although I would be open to Windows only solutions if necessary.


I’ve since had an attempt at implementing a streambuffer as suggested by doomster, with a little help from Filtering Streambufs by James Kanze. Unless any other suggestions come up, it seems like this is the closest you can get to the original suggestion. It won’t intercept C-style output, which I suspect that is either impossible or at impractical, but it otherwise provides all the functionality I wanted.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:05:12+00:00Added an answer on June 17, 2026 at 3:05 pm

    You can replace the streambuffer in order to intercept any output to those streams, see the rdbuf() function. I think you only need to implement the overflow() function in the streambuffer class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to execute a function at regular interval? I have a
Is there a way to execute a file but still be able to call
Is there a way to execute cURL requests through a VPN such as OpenVPN
Is there any way to execute two bash scripts without the first one blocking?
Is there a way to execute internal code via reflection? Here is an example
Is there a way to execute a .NET application compiled under AnyCPU as a
Is there a way to execute a JSF managed bean action when a page
Is there any way to execute arbitrary code in Flash, like javascript's eval()? I'd
Is there a way to Execute a custom program before InstallaWare removes the previous
I am wondering is there any way to execute following shell script, which waits

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.