我正在使用 VS 代码,但 cout 不起作用



我在 Ubuntu 19.04 上使用 VS 代码,我正在尝试运行一个非常简单的程序:

int main(int argc, char *argv[]) {
cout << "hello";
//some other simple stuff

我正在使用 gdb 逐步完成此代码。我的launch.json文件如下:

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/project1_debug",
"args": ["-c queue", "-f stack"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]

cout 下面的其他"简单东西"工作正常,只是cout不起作用。我检查了输出,问题和调试控制台,它们都没有显示任何输出。

这是我的调试控制台所说的:

Loaded '/lib64/ld-linux-x86-64.so.2'. Symbols loaded.
Breakpoint 1, main (argc=3, argv=0x7fffffffdeb8) at project1.cpp:6
6   int main(int argc, char *argv[]) {
Loaded '/lib/x86_64-linux-gnu/libstdc++.so.6'. Symbols loaded.
Loaded '/lib/x86_64-linux-gnu/libgcc_s.so.1'. Symbols loaded.
Loaded '/lib/x86_64-linux-gnu/libc.so.6'. Symbols loaded.
Loaded '/lib/x86_64-linux-gnu/libm.so.6'. Symbols loaded.
Breakpoint 2, main (argc=3, argv=0x7fffffffdeb8) at project1.cpp:8
8       cout << "hello";
Execute debugger commands using "-exec <command>", for example "-exec info registers" will list registers in use (when GDB is the debugger)
Kill the program being debugged? (y or n) [answered Y; input not from terminal]

我不明白为什么cout不起作用。

输出在终端选项卡中,从下拉菜单中选择"数字:cppdbg:文件名"标签

我只是在launch.json中将externalConsole设置为 true,现在我在外部控制台中获得了我想要的输出(即新的 bash(

#include <iostream>,如果您在此命名空间之外,请不要忘记使用std::cout

最新更新