为什么 Visual Studio 在调试时以不同方式处理 ANSI 转义码?
Why does Visual Studio treat ANSI Escape codes differently when debugging?
适用于:
- Visual Studio 社区版 2015 (C++)
- Windows 10
Visual Studio 有两种方法 运行 用于 Win32 控制台的 C++ 程序:"Start Without Debugging (Ctrl+F5)" 和 "Start Debugging (F5)"。两者都将为该程序启动一个单独的控制台 window。如果程序通过 cout
发送 ANSI 转义码,第一个 window 会按预期工作,但第二个会将代码显示为字符,不可打印的代码(例如 ESC)将替换为框中的问号。
为什么不一样?有没有办法让 ANSI 转义码在调试时正常运行?
2015年的文档没有说有限制(早期版本需要付费版本)。
使用 Visual Studio,您可以使用调试器附加到 运行ning 进程,这将避免该问题 — 前提是您的程序可以初始化并等待您执行此操作。
至于为什么不同,那可能是因为调试器在控制台window中拦截程序运行ning的input/output(并阻止它改变I/O 模式)。
进一步阅读:
- Attach to Running Processes with the Visual Studio Debugger (2015)
- How to: Attach to a Running Process (2010)
从后续评论中,@Sean-Gugler 意识到
- 可执行文件的 ANSI 代码在 运行 本地时未被解释(例如,从 文件资源管理器 打开),
- 但在 运行 正常情况下 来自 Visual Studio.
在被提醒 Windows 10 console window 解释 ANSI 转义序列时,
- 他验证了控制台 window 中预期的可执行文件 运行,并且
- 推测 Visual Studio 在调试 (F5) 时 运行 直接执行可执行文件(没有控制台 window),但是 did 运行 在控制台 window 当 运行 正常执行可执行文件时 (ctrlF5).
从 GUI(例如 Visual Studio)启动控制台应用程序的一个问题是应用程序必须做一些额外的工作来分配控制台。
进一步阅读:
- Can one executable be both a console and GUI application?
- Using the console in a GUI app in windows, only if its run from a console
- How to write to the console in a GUI application
适用于:
- Visual Studio 社区版 2015 (C++)
- Windows 10
Visual Studio 有两种方法 运行 用于 Win32 控制台的 C++ 程序:"Start Without Debugging (Ctrl+F5)" 和 "Start Debugging (F5)"。两者都将为该程序启动一个单独的控制台 window。如果程序通过 cout
发送 ANSI 转义码,第一个 window 会按预期工作,但第二个会将代码显示为字符,不可打印的代码(例如 ESC)将替换为框中的问号。
为什么不一样?有没有办法让 ANSI 转义码在调试时正常运行?
2015年的文档没有说有限制(早期版本需要付费版本)。
使用 Visual Studio,您可以使用调试器附加到 运行ning 进程,这将避免该问题 — 前提是您的程序可以初始化并等待您执行此操作。
至于为什么不同,那可能是因为调试器在控制台window中拦截程序运行ning的input/output(并阻止它改变I/O 模式)。
进一步阅读:
- Attach to Running Processes with the Visual Studio Debugger (2015)
- How to: Attach to a Running Process (2010)
从后续评论中,@Sean-Gugler 意识到
- 可执行文件的 ANSI 代码在 运行 本地时未被解释(例如,从 文件资源管理器 打开),
- 但在 运行 正常情况下 来自 Visual Studio.
在被提醒 Windows 10 console window 解释 ANSI 转义序列时,
- 他验证了控制台 window 中预期的可执行文件 运行,并且
- 推测 Visual Studio 在调试 (F5) 时 运行 直接执行可执行文件(没有控制台 window),但是 did 运行 在控制台 window 当 运行 正常执行可执行文件时 (ctrlF5).
从 GUI(例如 Visual Studio)启动控制台应用程序的一个问题是应用程序必须做一些额外的工作来分配控制台。
进一步阅读:
- Can one executable be both a console and GUI application?
- Using the console in a GUI app in windows, only if its run from a console
- How to write to the console in a GUI application