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 352831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:46:25+00:00 2026-05-12T11:46:25+00:00

How can you get unbuffered output from cout, so that it instantly writes to

  • 0

How can you get unbuffered output from cout, so that it instantly writes to the console without the need to flush (similar to cerr)?

I thought it could be done through rdbuf()->pubsetbuf, but this doesn’t seem to work. The following code snippet below is supposed to immediately output to the console, and then wait a few seconds. But instead, it just waits, and only outputs when the program exits and the buffer is flushed.

#include <iostream>

int main()
{
        std::cout.rdbuf()->pubsetbuf(0, 0);
        std::cout << "A";
        sleep(5);
}
  • 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-05-12T11:46:26+00:00Added an answer on May 12, 2026 at 11:46 am

    You can set the std::ios_base::unitbuf flag to flush output after each output operation either by calling std::ios_base::setf:

    std::cout.setf(std::ios::unitbuf);
    

    or using the std::unitbuf manipulator:

    std::cout << std::unitbuf;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can get individual frames from the iPhone's cameras just fine. what I need
I can get an html code from web site this way: public void Test()
I can get the list of country names using below code, (copied from somewhere
I can get JBPM version from db version as follows: JbpmVersion.getJbpmVersion(dbversion); But how to
I can get Cake to output a submit button using the following PHP: <?php
Can we get an ivar or a property from a NSString like we can
I can get the first record back from the code below in SQL Server
I can get an IAccessible object from a Firefox window using this code: Guid
I can get the artist, title and track information from the MediaStore, but how
I have a script on a shared host that uses suPHP. I need unbuffered

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.