官方有文档:
https://code.visualstudio.com/docs/?dv=osx
第一次用VS code, 似乎并没有传说中的好用。
vscode 本身只是个壳子,使用前需要安装各种插件。有点像vim?
c/c++
只要安装Microsoft 官方的那个c/c++
插件就可以了
然后是编译运行需要配置两个json文件。
下面是一个简单的helloworld的例子
- 负责编译的task.json(build 快捷键 control+shift+B)
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "test",
"type": "shell",
"command": "g++",
"args":["-g","test.cpp","-o", "test.o"],//此处需要修改
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
- 负责运行的launch.json(run 快捷键 F5)
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/test.o",//此处需要修改
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "lldb"
}
]
}
- 代码文件
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main(){
string x;
cin>>x;
cout<<"hello"<<endl;
return 0;
}
最后是 ctrl+p
可以打开一个命令行的东西,然后可以输入命令,比如:
ext install cpptools
C/CPP: Edit Configurations
Tasks: Configure Task Runner
Tasks: Run Tasks
有得文章中有提到那个设置系统头文件目录的json文件,没有这个文件我的程序也可以运行,不清楚是因为我用的mac,还是新版本的vscode不再需要这个文件?
参考:
这篇过程比较详细:
https://blog.csdn.net/lidong_12664196/article/details/68928136
makefile 方案:
https://blog.csdn.net/wzxlovesy/article/details/76708151