不得不吐槽下visual studio真是越来越大了。我的盘子表示鸭梨很大。于是乎,我遇见了vscode。
嘿嘿,再见Visual studio。
但是,vscode让人非常想吐槽的就是配置。。。因此在成功生成第一个exe文件后,我决定记录下这次成功的经历。
在此感谢JaJaCube,感谢大佬的教程才使得我成功运行。传送门:https://my.oschina.net/u/3669041/blog/1838710
打开vscode,选择或新建一个空文件夹目录打开作为项目目录,新建一个test.cpp文件,键入如下helloworld代码
#include<iostream>
using namespace std;
int main()
{
cout<<"hello world"<<endl;
}
按下F5,顶部或出现如下菜单,选择C++(GDB/LLDB)
系统自动在当前目录下创建.vscode文件夹,并在其中新建一个launch.json的模版文件,将该模版修改为如下(可以直接复制,并修改有注释的一段)
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"preLaunchTask": "build",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/mingw/bin/gdb.exe", // 这里修改GDB路径为安装的mingw64的bin下的gdb.exe路径
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}]
}
vscode中按下组合键Shift+Ctrl+P,在唤出的任务栏中键入>task,下拉找到并点击 Tasks:Configure Task(任务:配置任务)项,并在接下来的返回项中选择使用模版创建tasks.json文件
系统会自动在.vscode文件夹下创建一个tasks.json文件,自动生成的代码修改为如下代码(可直接覆盖)
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"windows": {
"command": "g++",
"args": [
"-ggdb",
"\"${file}\"",
"--std=c++11",
"-o",
"\"${fileDirname}\\${fileBasenameNoExtension}.exe\""
]
}
}
]
}
至此,环境配置完成,转到C++代码页,按下F5,根目录下出现.cpp文件同名的.exe文件,代码自动执行,完成。