C++: cannot see output in VS Code while debugging

最后都变了- 提交于 2020-06-17 15:49:50

问题


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"

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

Edit 1

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

Edit 2

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";
    }
}

回答1:


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".



来源:https://stackoverflow.com/questions/61869567/c-cannot-see-output-in-vs-code-while-debugging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!