2

I'm following this tutorial: https://www.learncpp.com/cpp-tutorial/basic-debugging-tactics/

The output at the end of section Debugging tactic #2: Validating your code flow is supposed to be:

main() called
getValue() called
4

but in CLion I am seeing:

4main() called
getValue() called

Similarly, in section Debugging tactic #3: Printing values the output should be:

Enter a number: 4
main::x = 4
Enter a number: 3
main::y = 3
4 + 3
main::z = 9
The answer is: 9

I'm seeing:

Enter a number: 4
Enter a number: main::x = 4
3
main::y = 3
main::z = 9
4 + 3
The answer is: 9
Zaku
  • 180
  • 6
  • 1
    you are interleaving the output from cerr and cout - i think the buffereing / ordering is not defined – pm100 Oct 18 '22 at 22:41
  • Try to use `std::flush` after each output to `cout` to make sure it actually prints immediately. Otherwise it flushes whenever the implementation feels like it (usually when the buffer is full) or on certain blocking operations like reading from `cin`. – François Andrieux Oct 18 '22 at 23:48
  • Possible duplicate : [When does cout flush?](https://stackoverflow.com/questions/22345226/when-does-cout-flush) – François Andrieux Oct 18 '22 at 23:51

0 Answers0