用 vscode 运行 c++ 代码,报错

用 vscode 运行c++代码,报错:

终端:

     "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-za3jxu32.ywg" 1>"/tmp/Microsoft-MIEngine-Out-32lhdfrr.3fy"

调试控制台:


```bash
thread-group-added,id="i1"
GNU gdb (Ubuntu 11.1-0ubuntu2) 11.1
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
=cmd-param-changed,param="pagination",value="off"
Stopped due to shared library event (no libraries added or removed)
Loaded '/lib64/ld-linux-x86-64.so.2'. Symbols loaded.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, main () at /home/wushuning/myWork/codeC/hello/test.c:5
5        printf("hello");
Loaded '/lib/x86_64-linux-gnu/libc.so.6'. Symbols loaded.
[Inferior 1 (process 18456) exited normally]
The program '/home/wushuning/myWork/codeC/hello/test' has exited with code 0 (0x00000000).


```

30行程序返回值为0,程序正常结束运行。
输出内容在终端哩。

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 帮你找了个相似的问题, 你可以看下: https://ask.csdn.net/questions/7647744
  • 我还给你找了一篇非常好的博客,你可以看看是否有帮助,链接:用VScode运行第一个C++程序~~
  • 除此之外, 这篇博客: VScode C++ 开发 (七):实战篇及Vscode调试中的 参考 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:

    B站UP主:xiaobing1016

  • 以下回答由chatgpt基于相关博客总结生成:

    首先,我们需要确保已经正确配置了vscode的C++编译和调试环境。我们可以按照以下步骤进行配置:

    1. 安装MinGW或其他可用的C++编译器。确保将编译器添加到系统的环境变量中,以便可以在终端中运行g++命令。

    2. 在.vscode文件夹下的tasks.json文件中配置构建说明。在tasks.json文件中,可以指定编译和运行C++代码的任务。在给定的参考资料中,未提供tasks.json的具体内容,因此你可以根据你的编译器和操作系统进行相应的配置。

    3. 在.vscode文件夹下的launch.json文件中配置调试器设置。可以使用debug配置来设置断点,观察变量和执行程序等。在给定的参考资料中,未提供launch.json的具体内容,因此你可以根据你的需要进行相应的配置。

    4. 在.vscode文件夹下的c_cpp_properties.json文件中配置编译器路径和IntelliSense设置。在c_cpp_properties.json文件中,可以指定编译器的路径和其他相关设置。在给定的参考资料中,未提供c_cpp_properties.json的具体内容,因此你可以根据你的编译器和操作系统进行相应的配置。

    接下来,我们需要检查报错信息,以便更好地理解问题。请提供终端和调试控制台的输出内容。根据报错信息,我们可以进一步分析问题并提供解决方案。

    最后,你可以尝试使用以下步骤解决问题:

    1. 确保你所使用的操作系统和vscode的版本信息,并提供这些信息,以便进行更精确的解答。

    2. 检查你的C++代码是否存在语法错误或其他逻辑错误。确保代码可以正常编译和运行。

    3. 检查你的vscode的C++配置,确保编译器路径和其他设置正确。

    如果以上步骤没有解决你的问题,那么很遗憾,我无法给出具体的解决方案。请尝试在相关编程社区或咨询专业人士寻求更多帮助。


如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^