【无法使用命令行 code】
打开 vscode 后,打开命令面板(按 cmd+shift+p)选择
shell command: install “code" command in PATH
现在就可以在终端执行 code 了,但重启后可能会失效,如希望启动即可使用命令行,参考:
mac通过终端code 命令打开vscode_SailorCai的博客-优快云博客_mac vscode打开终端
【生成 3个重要的 json 配置文件】
命令面板,选择 C/C++: Edit Configurations (JSON) ,生成 c_cpp_properties.json
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-arm64"
}
],
"version": 4
}
点击右上角三角运行图标,选择 C/C++: clang++ 生成和调试活动文件,生成 tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ 生成活动文件",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
尝试编写代码后,发现 vector 初始化报错,无法编译通过。
自动生成的 tasks.json 中需要手动添加,才可正常编译,原因还未探明。
"-std=c++17",
"-stdlib=libc++",