目录
提前准备
配置
c_cpp_properties.json
task.json
settings.json
launch.json
注:
提前准备
Download Visual Studio Code - Mac, Linux, Windowshttps://code.visualstudio.com/Download
配置
新建一个文件夹,名字随意
打开vscode,写一个文件
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1005
#define N 500005
#define debug(...) cout << '[' << 'D' << 'E' << ']' << __LINE__ << ':' << __VA_ARGS__ << endl;
#define v(x) #x << '(' << x << ')'
#define mod 998244353
#define who(s,limit,tpe) s + tpe , s + limit + tpe
#define all(s) s.begin(),s.end()
#define s_(s) s.size()
int a[N];
string s;
int main(){
int n;
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
cout << n + 1 << endl ;
}
命名为a.cpp
存在你新建的文件夹里 : command + s,以后保存编辑的时候也要用
command + shift + p:
c_cpp_properties.json
选择最后一个
新建一个c_cpp_properties.json,把里面的代码改成
{
"configurations": [
{
"name": "Mac",
"defines": [],
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks",
"${workspaceFolder}/**"
],
"compilerPath": "/usr/bin/g++",
"cStandard": "c11",
"cppStandard": "c++14",
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
task.json
command + shift + p, 输入task,
选择第一个
选择“C/C++: cpp 生成活动文件”
插入如下一段:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "msbuild",
"args": [
"/property:GenerateFullPaths=true",
"/t:build",
"/consoleloggerparameters:NoSummary"
],
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
},
{
"type": "cppbuild",
"label": "C/C++: clang++ 生成活动文件",
"command": "/usr/bin/clang++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "编译器: /usr/bin/clang++"
},
{
"type": "cppbuild",
"label": "C/C++: cpp 生成活动文件",
"command": "/usr/bin/cpp",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "编译器: /usr/bin/cpp"
}
]
}
settings.json
command + shift + p ,输入settings
?把里面的代码改成:
{
"python.pythonPath": "/Users/zjx/anaconda3/bin/python3",
"code-runner.executorMap": {
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
},
"editor.renderWhitespace": "all",
"editor.renderLineHighlight": "all",
"editor.formatOnSave": true,
"code-runner.runInTerminal": true,
"code-runner.ignoreSelection": true,
"code-runner.enableAppInsights": false,
"C_Cpp.updateChannel": "Insiders",
"[makefile]": {
"editor.insertSpaces": true
},
"C_Cpp.default.includePath": [
"/usr/local/opt/opencv@3/include"
// "/usr/local/Cellar/opencv/4.0.1/include/opencv4"
// "/usr/local/include/opencv4"
],
"files.associations": {
"iosfwd": "cpp",
"iostream": "cpp",
"ostream": "cpp",
"random": "cpp"
},
"C_Cpp.errorSquiggles": "Disabled"
}
launch.json
?点击后,选择(LLDB 和 c++有关的):
把里面的代码改成:
{
//
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.out",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": true, // if true then stop at the main entry (function)
"environment": [],
"externalConsole": true,
"MIMode": "lldb",
"preLaunchTask": "build hello world"
}
]
}
写完之后就结束了
返回你刚刚写的代码?
按下F5,
等编辑完之后
再按右上角的小三角,就OK了.
注:
? ? ? ? 想放大要按command + “+”
|