
答案1
安裝支援 C++ 的 IDE。 Visual Studio Code 是一個功能齊全的程式碼編輯器,但它不是像 Visual Studio 這樣的 IDE。任何支援 C++ 的常用 IDE 都可以。 XCode 是一個非常簡潔的 IDE,具有內建的 C++ 編譯器,因此您可以編寫 C++,只需點擊即可編譯並運行。
答案2
我可以在 MacOS 上的 VSCODE 中建立 C++17 程式碼,配置如下:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "clang++ build active file",
"command": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++",
"args": [
"-g",
"${file}",
"-std=c++17",
"--debug",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin"
},
"problemMatcher": [
"$gcc"
]
}
]
}
答案3
要在 macOS 上的 VSCode 中建置和偵錯 C++ 程式碼,您應該遵循本教程
您的 c_cpp_properties.json(位於專案資料夾中的 .vscode 資料夾中)應如下所示(將 YOURUSERNAME 替換為您的 macOS 使用者名稱):
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/Users/YOURUSERNAME/bin/CPP_Libraries/Eigen/Eigen/**"
],
"defines": [],
"macFrameworkPath": ["/System/Library/Frameworks",
"/Library/Frameworks"],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}