Reputation: 779
Applies to:
Visual Studio has two ways to run a C++ program for Win32 Console: "Start Without Debugging (Ctrl+F5)" and "Start Debugging (F5)". Both will launch a separate console window for the program. If the program sends ANSI escape codes via cout
, the first window works as expected, but the second will show the codes as characters, with unprintable codes such as ESC replaced by a question mark in a box.
Why is it different? Is there a way to get the ANSI escape codes to behave normally while debugging?
Upvotes: 2
Views: 1754
Reputation: 54583
The 2015 documentation does not say that there is a restriction (earlir versions required the paid version).
With Visual Studio, you can use the debugger to attach to a running process, which would avoid the problem — provided that your program can initialize and wait for you to do this.
As for why it is different, that is probably because the debugger is intercepting the input/output of the program running in the console window (and preventing it from changing the I/O modes).
Further reading:
From followup comments, @Sean-Gugler realized that
On being reminded that Windows 10 console window interprets ANSI escape sequences,
One of the problems in starting a console application from a GUI (such as Visual Studio) is that the application would have to do some extra work to allocate a console.
Further reading:
Upvotes: 2