官网下载,Documentation for Visual Studio Codehttps://code.visualstudio.com/docs/?dv=osx
打开后,在刚进去的页面,安装git
下插件,
终端安装cmake。
brew install cmake
出现brew command not found的问题原因是因为机器上没有brew程序,机器上安装即可:Mac如何安装brew?_赫赫phper的博客-优快云博客_mac 安装brew
/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"
完成后,根据提示,执行下面命令将 Homebrew 到 PATH 中:
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/wangzheng/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
下面配置环境引自:无废话--Mac OS, VS Code 搭建c/c++基本开发环境 - 知乎
打开一个包含.cpp文件的文件夹(没有就自己创建)
“command+shift+p”打开命令行工具窗口,输入或者选择“
Edit Configurations”命令。
此时会在当前工作空间目录生成.vscode配置目录,同时在配置目录会生成一个c_cpp_properties.json文件。
配置include目录:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/Library/Developer/CommandLineTools/usr/include/c++/v1",
"/usr/local/include",
"/Library/Developer/CommandLineTools/usr/lib/clang/9.0.0/include",
"/Library/Developer/CommandLineTools/usr/include",
"/usr/include"
],
"defines": [],
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
6)
“command+shift+p”打开命令行工具窗口,输入或者选择“Tasks: Configure Task”
task.json内容如下:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "c++",
"command": "clang++",
"type": "shell",
"args": [
"./c++/hello.cpp",
"-std=c++11",
"-g"
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
}
}
]
}
7)配置launch.json。
“command+shift+p”打开命令行工具窗口,输入或者
选择Debug: Open launch.json命令。
修改内容如下:
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "c/c++ Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "lldb",
"preLaunchTask":"c++"
}
]
}
8)开启调试
中途可能会提醒控制终端,需要赋予权限,允许即可。
vscode要写c++时iostream头文件找不到
gcc -v -E -x c++ - (或者gcc -v -E -x c++ -)
终端会输出一大堆东西:
复制
include "..." search starts here: include <...> search starts here:这两个之后的内容,最底下那行end啥的不用
加到c_cpp_properties.json里的includePath里 保存好后
关了vscode再从打开把头文件那两句重打一下就成了
解决c++中的cin问题: