C ++:调试时看不到VS Code中的输出 [英] C++: cannot see output in VS Code while debugging

查看:2518
本文介绍了C ++:调试时看不到VS Code中的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我试图从VS2019切换到VS Code,同时继续使用MSVC。这样,我通常会在轻量级且更轻松的环境中进行开发,并且当我需要高级知识(例如查看热路径)时,就可以打开VS2019并完成工作。下面是我的 launch.json 配置

Today I'm trying to switch from VS2019 to VS Code while keep working with MSVC. This way I will develop in a lightweight and easier environment most of the time, and when I need advanced stuff such as seeing hot paths, I would be able to open VS2019 and do the job. Below is my launch.json configuration

"name": "debug",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/build/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"preLaunchTask": "compile"

问题是调试 std :: cout 的输出时,在任何窗口中都看不到。将 externalConsole 设置为 true 会打开一个新控制台,其中的结果是预期的结果。没有新的控制台,有没有办法查看程序的输出?一段时间以前,当我使用Node时,我记得 console.log() DEBUG CONSOLE 窗口中可见

The problem is that when debugging the output from std::cout cannot be seen in any window. Setting externalConsole to true opens a new console where the results are the expected ones. Is there a way to see the output of my program without a new console? When I worked with Node some time ago I remember that console.log() was visible in the DEBUG CONSOLE window

我在下面添加了底部4个选项卡的屏幕快照,以进行澄清。如您所见,调试控制台没什么。最后一个图像是外部控制台。我发现大约60秒后, DEBUG CONSOLE 窗口显示正确的内容,然后我猜又冻结了60秒。程序应在无限循环中显示行。最后的屏幕快照在修改 launch.json

I added screenshots of the bottom 4 tabs below for clarifying. As u can see DEBUG CONSOLE yeild nothing. The last image is the external console. I found that after ~ 60 secs the DEBUG CONSOLE window displays the right thing, and then I guess freezes again for another ~ 60 secs. The program should display lines in an infinite loop. The last screenshot is took in another debug session, after modifying launch.json





下面是两个示例。第一个按预期工作。第二个没有。在我的初始程序中,执行了与第二个示例相似的操作

Below are 2 examples. The first one works as intended. The second one does not. In my initial program something similar to the second example was executed

#include <iostream>
using namespace std;
int main() {
    std::cout << "Hello world!\n";
}



#include <iostream>
#include <Windows.h>
using namespace std;
int main() {
    while(true) {
        Sleep(500);
        std::cout << "Hello world!\n";
    }
}


推荐答案

您可能看错了选项卡。应该有选项卡问题,输出,调试控制台和终端。为什么要按F5键,您就处于终端位置。这就是执行启动任务的外壳。但是,您从std :: cout输出的程序将进入调试输出。

You are probably looking at the wrong tab. There should be the tabs "Problems", "Output", "Debug Console" and "Terminal". Why you hit F5 you are in "Terminal". That's the shell where your launch task get's executed. Your program output from std::cout however goes into "Debug Output".

这篇关于C ++:调试时看不到VS Code中的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆