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

  • Home
  • SEARCH
  • 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 9153423
In Process

The Archive Base Latest Questions

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

Possible Duplicate: Why does my cout output not appear immediately? I have a very

  • 0

Possible Duplicate:
Why does my cout output not appear immediately?

I have a very heavy method (it checks if a number is a prime – Euler 3), which blocks cout.
How is this possible? This is my code:

int main(int argc, char * argv[]) {
    cout << "-----------------------------------------------------------" << endl;
    cout << "isPrime(3): " << ((isPrime(3)) ? "true" : "false") << endl;
    cout << "isPrime(10): " << (isPrime(10) ? "true" : "false") << endl;
    cout << "BLAH";
    cout << "BLAH";
    cout << "BLAH";
    cout << "BLAH";
    cout << "BLAH";
    cout << "BLAH";
    cout << "isPrime(600851475143): " << (isPrime(600851475143.0) ? "true" : "false") << endl; // This one takes very long to complete
    cout << "-----------------------------------------------------------";
}

Like this, it outputs:

[Session started at 2013-01-19 13:50:12 +0100.]
-----------------------------------------------------------
isPrime(3): false
isPrime(10): false

and then stops (for a few minutes). (isPrime() is broken, I know!)
If I comment the line with isPrime(600851475143) out, it outpus everything except the output of the commented line of course in less than a second.

How is it possible that a very heavy method call blocks output that should already have been written to cout?

  • 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-17T12:16:11+00:00Added an answer on June 17, 2026 at 12:16 pm

    cout writes to the standard output, which is typically line-buffered. i.e. the buffer is only flushed to the console when it encounters a newline character or an endl, or when you explicitly call cout.flush().

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

Sidebar

Related Questions

Possible Duplicate: Does std::list::remove method call destructor of each removed element? I have a
Possible Duplicate: Does std::list::remove method call destructor of each removed element? I have a
Possible Duplicate: What does “(void) new” mean in C++? I'm not familiar with C++
Possible Duplicate: Why does the background of TextView change it's size? I have a
Possible Duplicate: Does every Core Data Relationship have to have an Inverse? I have
Possible Duplicate: Does anyone beside me just NOT get ASP.NET MVC? I dont know
Possible Duplicate: Does an open-ended interval implementation exist for Java? i have an int
Possible Duplicate: Why does this simple std::thread example not work? Code: #include <iostream> #include
Possible Duplicate: Does the Facebook 'like' have a limit? Facebook like button updates the
Possible Duplicate: Does glob() have negation? I want to delete all files from a

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.