The Problem: Buffering of output can lead to unexpected results For example: std::cout << “Doing unrelated stuff” << std::endl; do_stuff(); std::cout << “Doing divide ... “; i = 1/0; // Divide by zero std::cout << “complete\n”; When runs this program prints (on some systems): Doing unrelated stuff Floating point exception8 From this output we can see that the problem is “obviously” in the do_stuff function. What's going on? The problem is that output is being buffered. So the string “Doing divide ...” goes into the buffer, then the program crashes with a divide by zero error, and the output is never displayed. This is where the confusion comes from

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter6: Modularity Using Functions
Section6.4: A Case Study: Rectangular To Polar Coordinate Conversion
Problem 9E: (Numerical) Write a program that tests the effectiveness of the rand() library function. Start by...
icon
Related questions
Question

The Problem: Buffering of output can lead to unexpected results
For example:
std::cout << “Doing unrelated stuff” << std::endl;
do_stuff();
std::cout << “Doing divide ... “;
i = 1/0; // Divide by zero
std::cout << “complete\n”;
When runs this program prints (on some systems):
Doing unrelated stuff
Floating point exception8
From this output we can see that the problem is “obviously” in the
do_stuff function. What's going on?
The problem is that output is being buffered. So the string
“Doing divide ...” goes into the buffer, then the program crashes with a
divide by zero error, and the output is never displayed. This is where the
confusion comes from

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Hash Table
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr