赞
踩
下载地址:https://code.visualstudio.com/
下载地址:https://sourceforge.net/projects/mingw-w64/files/
下载时勾选相关文件
需要设置环境变量,使用下面的指令检查安装是否成功。
gcc -v
在左侧工具栏的扩展中下载C/C++插件。
新创建一个文件夹,用于存放代码。然后用VS Code打开找个文件夹。
c_cpp_properties.json
,tasks.json
,launch.json
这3个配置文件均可以手动创建,放在.vscode
文件夹下。
快捷键Ctrl+Shift+P调出命令面板,输入C/C++
,选择Edit Configurations(UI)
进入配置。设置编辑器路径和IntelliSense模式。
编译器路径设置为D:/Download/MinGW/bin/g++.exe
。
IntelliSense
模式设置为gcc-x64
。
配置完成后,此时在侧边栏可以发现多了一个.vscode
文件夹,并且里面有一个c_cpp_properties.json
文件,内容如下,说明上述配置成功。compilerPath
改为自己安装的路径。
{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "windowsSdkVersion": "10.0.18362.0", "compilerPath": "D:/Download/MinGW/bin/g++.exe", "cStandard": "c17", "cppStandard": "c++17", "intelliSenseMode": "gcc-x86" } ], "version": 4 }
快捷键Ctrl+Shift+P调出命令面板,输入tasks
,选择Tasks:Configure Default Build Task
进行配置。调用g++编译器基于源代码创建可执行文件。
然后再点击g++.exe build active file
。
此时.vscode
文件夹中出现一个名为tasks.json
的配置文件,这个文件也可以手动创建。command
和cwd
改为自己安装的路径。
{ "version": "2.0.0", "tasks": [ { "type": "shell", "label": "g++.exe build active file", // g++的路径 "command": "D:/Download/MinGW/bin/g++.exe", "args": [ // 添加gdb调试选项 "-g", "${file}", // 指定生成可执行文件的名称 "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "D:/Download/MinGW/bin" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", // 表示快捷键Ctrl+Shift+B可以运行该任务 "isDefault": true } } ] }
点击菜单栏的启动调试
。
选择C++(GDB/LLDB)
。
此时.vscode
文件夹中出现一个名为launch.json
的配置文件,修改文件内容。
如果报错Unable to create 'launch.json' file inside the '.vscode' folder (Cannot read property 'name' of undefined).
的话,手动创建即可。miDebuggerPath
改为自己安装的路径。
{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { // 配置名称,将会在启动配置的下拉菜单中显示 "name": "(gdb) Launch", // 调试前执行的任务,就是之前配置的tasks.json中的label字段 "preLaunchTask": "g++.exe build active file", // 配置类型,只能为cppdbg "type": "cppdbg", // 请求配置类型,可以为launch(启动)或attach(附加) "request": "launch", // 调试程序的路径 "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", // 程序调试时传递给程序的命令行参数,一般设为空即可 "args": [], // 设为true时程序将暂停在程序入口处,一般设置为false "stopAtEntry": false, // 调试程序时的工作目录,一般为${workspaceFolder}即代码所在目录 "cwd": "${workspaceFolder}", "environment": [], // true显示外置的控制台窗口,false显示内置终端 "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "D:/Download/MinGW/bin/gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
路径不要有中文!!否则会报错。按F5运行程序。
#include<stdio.h>
// system头文件
#include <stdlib.h>
int main()
{
printf("Hello C!\n");
system("pause");
return 0;
}
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello C++!"<<endl;
system("pause");
return 0;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。