Visual Studio 2019 hanging in cout/printf

Tyler 1 Reputation point
2021-10-10T17:28:29.87+00:00

When debugging in Visual Studio 2019, any time my program attempts to cout or print it causes the debugger to stall infinitely. If I pause the debugger and look at the main thread, it will always be in 'ucrtbased.dll!write_text_ansi_nolock' once it gets stalled.

When I run the built exe on it's own, it prints to console perfectly fine. The stalling happens while the application is single threaded, just trying to console print out a single line of text with no variables.

How can I fix this, or look inside the above DLL to see what is happening?

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,537 questions
{count} votes

6 answers

Sort by: Most helpful
  1. Octavi 0 Reputation points
    2023-11-22T13:24:26.3933333+00:00

    In my case, it got fixed by focusing on the cmd window and pressing space.

    I guess (but I am not sure) that what happened was that I clicked on the cmd window and selected something by mistake; this usually freezes the application until you press a key and the selection disappears from the cmd window.

    At least, I can reproduce it: just start debugging, click and drag on the cmd window (so something is selected), and then restart the debugger session. It will freeze in the WriteFile() of the write_text_ansi_nolock(). If you restart the debugging session (by pressing the stop button and play button in VS 2022), it freezes again at the same place. Once you focus on the cmd window and press a key, so the selection disappears, everything goes back to normal.

    I am not sure that this is happening to anyone else, but at least it's something to try out.

    I hope it helps someone :)

    0 comments No comments