VSCode编写C/C++语言,配置文件和注意事项
Posted tsruixi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VSCode编写C/C++语言,配置文件和注意事项相关的知识,希望对你有一定的参考价值。
前言
主要是自己先下载好VSCode,然后在自己电脑上安装好就行了,但是VSCode是编辑器,不是IDE,所以需要自己配置文件,主要有四个都是以.json
结尾的文件,这里默认已经装过C/C++的编辑器,也就意味着电脑上有MINGW64,也就说明你自己先要找到他们的路径为后续配置做好准备。
- 把gcc.exe,gdb.exe的路径添加到环境变量里面,也就是MINGW64的bin目录。
- 开始打开一个文件夹,在VSCode中打开一个文件夹,然后创建一个cpp程序。再点开调试栏,然后生成文件。或者自己创建一个
.vscode
文件夹,把四个文件都放入其中。 - 把下面的几个.json文件,内容分别替换成下面的内容。
launch.json
关键的路径换成自己的就行
"version": "0.2.0",
"configurations": [
"name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示
"type": "cppdbg", // 配置类型,这里只能为cppdbg
"request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
"program": "$workspaceFolder/$fileBasenameNoExtension.exe",// 将要进行调试的程序的路径
"args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可
"stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false
"cwd": "$workspaceFolder", // 调试程序时的工作目录,一般为$workspaceFolder即代码所在目录
"environment": [],
"externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台
"MIMode": "gdb",
"miDebuggerPath": "D:\\collage_3\\C_language\\Dev-Cpp\\MinGW64\\bin\\gdb.exe", // miDebugger的路径,注意这里要与MinGw的路径对应
"preLaunchTask": "g++", // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc
"setupCommands": [
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
]
]
task.json
"version": "2.0.0",
"command": "g++",
"args": ["-g","$file","-o","$fileBasenameNoExtension.exe"], // 编译命令参数
"problemMatcher":
"owner": "cpp",
"fileLocation": ["relative", "$workspaceFolder"],
"pattern":
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
c_cpp_properties.json
"configurations": [
"name": "Win32",
"includePath": [
"$workspaceFolder/**",
"D:/collage_3/C_language/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++",
"D:/collage_3/C_language/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/x86_64-w64-mingw32",
"D:/collage_3/C_language/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/backward",
"D:/collage_3/C_language/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include",
"D:/collage_3/C_language/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../include",
"D:/collage_3/C_language/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include-fixed",
"D:/collage_3/C_language/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:\\collage_3\\C_language\\Dev-Cpp\\MinGW64\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++14",
"intelliSenseMode": "clang-x64"
],
"version": 4
setting.json
"C_Cpp.errorSquiggles": "Disabled",
"files.associations":
"cstdlib": "cpp"
以上是关于VSCode编写C/C++语言,配置文件和注意事项的主要内容,如果未能解决你的问题,请参考以下文章