
c++b4f0734bfe6d1eb06384Microsoft YaHei", "SF Pro Display", Roboto, Noto, Arial, "PingFang SC", sans-serif; color: rgb(79, 79, 79); line-height: 32px; overflow-wrap: break-word; font-variant-ligatures: common-ligatures; white-space: normal; background-color: rgb(255, 255, 255);">安装微软C/C++插件
在vs code的扩展图标里搜索c++,安装c/c++插件并重载vs code

重启VS Code之后,打开一个含c/c++源码的文件夹,VS Code将会创建一个名为.vscode的子文件夹用于存放配置文件。
安装MinGW
去官网下载安装器,安装好后选择需要安装的工具:
立即学习“C++免费学习笔记(深入)”;

选择好之后应用更改:

然后修改系统的环境变量,将可执行文件目录加入到Path中:

智能提示
为实现代码补全,需要创建一个c_cpp_properties.json文件。新建一个hello.c,输入:
#include <stdio.h>
int main(void)
{
printf("hello");
getchar();
return 0;
}VS Code会提示找不到头文件,点击错误处的小灯泡,编辑包含路径

在c_cpp_properties.json中修改Win32下的路径设置
"browse": {
"path": [
"${workspaceRoot}",
"C:\DevProgram\MinGW\lib\gcc\mingw32\6.3.0\include\c++"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}返回编辑器,点击小灯泡,将头文件所在目录添加到包含路径中

构建程序
构建程序需要创建一个tasks.json文件,点击任务->配置任务:

在弹出的选项中选择Others,然后修改tasks.json
{
"version": "2.0.0",
"tasks": [
{
"taskName": "build hello",
"type": "shell",
"command": "g++",
"args": [
"-g", "hello.c"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}调试代码
调试代码需要创建一个launch.json文件,点击调试栏的齿轮图标

修改launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\DevProgram\MinGW\bin\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build hello"
}
]
}调试运行
返回编辑器,设置断点,按F5开始调试

相关文章教程推荐:vscode教程
以上就是#%#$#%@%@%$#%$#%#%#$%@_e2fc++805085e25c9761616c00e065bfe8如何编译运行c/c++程序的详细内容,更多请关注php中文网其它相关文章!
c++怎么学习?c++怎么入门?c++在哪学?c++怎么学才快?不用担心,这里为大家提供了c++速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号