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,879 questions
{count} votes

6 answers

Sort by: Most helpful
  1. Abraham Martin 11 Reputation points
    2022-11-28T15:53:15.203+00:00

    For what it's worth, I managed to solve this closing VS removing the .vs folder and running VS again. Other times it just stopped the same way it appeared: no code changes, no build, just one debugging session is ok, the next one it stops in the 1st printf. It happens with boost calls to (stream_type::write() -> logging system) too, so I suspect "someone" (SO, antivirus?) is not letting VS to write anything out... just guessing.

    It happens to me in visual studio 2022 too (using 2019 compilers, I have both VS installed).

    2 people found this answer helpful.
    0 comments No comments

  2. Justin Ferguson 5 Reputation points
    2023-03-28T21:54:36.4766667+00:00

    I've had this problem intermittently for years across multiple versions of Visual Studio-- its never in a clean-cut example which makes it hard to reproduce and/or report. I've not looked at what's occurring at an assembly level, but its always in a printf/std::cout et al.

    To fix it temporarily, that is to step past the problem until it crops up again-- reboot. To remedy the issue apparently permanently do as suggested by Abraham and delete the .vs folder in the solutions parent directory then restart visual studio.

    1 person found this answer helpful.
    0 comments No comments

  3. Octavi 5 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 :)

    1 person found this answer helpful.

  4. Dan Honeycutt 1 Reputation point
    2022-09-19T15:31:15.617+00:00

    Has anything more developed on this issue? I have the same problem. My version:

    Microsoft Visual Studio Community 2022 (64-bit) - Current
    Version 17.2.6

    Thanks for any help.
    Dan Honeycutt


  5. Minxin Yu 13,011 Reputation points Microsoft External Staff
    2023-03-29T05:49:36.12+00:00

    delete the .vs folder in the solutions parent directory then restart visual studio.

    It is recommended that the problem be reported to the Developer Community. And it would be helpful to provide a minimal reproducible example.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.