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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:20:12+00:00 2026-06-12T23:20:12+00:00

I am curious about how cout work with bus/segmentation errors. I have two examples

  • 0

I am curious about how cout work with bus/segmentation errors. I have two examples pasted below. Because I don’t know how to replicate a bus error you have to take if from me that grid.DoMovement, in this example, throws a bus error. While I was cout-ing something before the bus error line I noticed that if I put an endline in it will print it out fine, but if I don’t put an endl in it does not. The examples at the bottom show what I mean.

Why is it that if you don’t put an endline in the cout and you have a bus error on one of the later lines that it doesn’t print out the “example 2”?

Example 1:

std::cout << "example 1" << endl;
grid.DoMovement(); 

Output is

works
bus error

Example 2:

std::out << "example 2";
grid.DoMovement(); 

Output is

bus error
  • 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-12T23:20:13+00:00Added an answer on June 12, 2026 at 11:20 pm

    By default IOStreams are buffered. Anything only written to the buffer won’t be displayed. When you use std::endl with a stream a newline gets added and the stream is flushed. Note, that normally you don’t want to have the stream flushed: Frequent flushing of flie streams can reduce performance dramatically! Thus, it is a good idea not to use std::endl but '\n' if you want a newline. If you really want to flush a stream you can explicitly use std::flush which just flushes the stream.

    During debugging it may be helpful to have all output appear as soon as it is written so that a crash doesn’t prevent output from showing. If you follow the above advise and don’t flush frequently a lot of output may get buffered. The simple remedy for this is to use std::unitbuf: this manipulator turns on the flag std::ios_base::unitbuf cause the output streams to be flushed after each insertion. You can turn the flag off again using std::nounitbuf to avoid slowdown in code sections which are known to work (or, at least, known not to fail in a too dramatic way):

    std::cout << std::unitbuf;   // turn on automatic flushing
    problematic_code();
    std::cout << std::nounitbuf; // turn off automatic flushing
    

    The default settings for the std::ios_base::unitbuf is the differences between std::cerr and std::clog: both stream write to the standard error stream (on UNIXes file descriptor 2) but std::cerr flushes its buffer after each write while std::clog does not.

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

Sidebar

Related Questions

I am a little curious about the last lines in the two examples presented
Curious about running multiple xvfb displays: I have between 10-50 instances of a script
I am a bit curious about how this works - if I have 5
I am curious about COM+, DCOM. I know that MSFT does not encourage you
Just curious about a particular scenario of NAT. Let's suppose we have 4 computers
Just curious about how jaxb works, I have a class annotated as follows: @XmlRootElement(name
I am curious about the use of the function named test (line 3) below:
Just curious about SQL syntax. So if I have SELECT itemName as ItemName, substring(itemName,
Just curious about the control shown below, the straight line with label beside it.
I was just curious about this to see how this might work. $number =

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.