C++ Mac VSCode调试器始终显示关于';的错误';和';:';
我正在尝试在Mac上设置vscode环境。我遵循网站上的程序 但当我试着调试我的程序时,它显示出错误并且无法跳过。 我不确定这是因为版本或其他原因C++ Mac VSCode调试器始终显示关于';的错误';和';:';,c++,c++11,visual-studio-code,vscode-settings,vscode-debugger,C++,C++11,Visual Studio Code,Vscode Settings,Vscode Debugger,我正在尝试在Mac上设置vscode环境。我遵循网站上的程序 但当我试着调试我的程序时,它显示出错误并且无法跳过。 我不确定这是因为版本或其他原因 #include <iostream> #include <vector> #include <string> using namespace std; int main() { vector<string> msg {"Hello", "C++++", "World", "from", "VS C
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> msg {"Hello", "C++++", "World", "from", "VS Code", "and the C++ extension!"};
for (const string& word : msg)
{
cout << word << " ";
}
vector<string> aaa {"H", "E", "L", "L", "O"};
for (const string& word : aaa)
{
cout << word << " ";
}
cout << endl;
}
我的task.json文件是
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
你让它起作用了吗?我在.vscode目录中添加了一个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": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
而且我能够调试相同的代码示例我也面临同样的问题。但问题是,默认情况下C/C++配置与教程中显示的不同。因此,如果您一步一步地遵循教程,您可能最终不会配置c/c++编译器来使用它。我所做的是跳过调试步骤,直接转到C/C++配置步骤,然后添加.vscode/C_cpp_properties.json,如教程所示(也由上面帖子中的@Bill提供)。
然后,如果您尝试调试,它将不会显示该错误,因为现在您已将编译器配置为c++17。请不要发布代码图像或错误消息。请参阅,以获取原因列表。代码和错误消息都是文本信息,应该以这种形式直接复制/粘贴到您的问题中。您需要将c++17标志添加到intellisense编译器中(尽管我不能说如何在VScode中这样做),我不确定您的意思。你能告诉我更多的细节吗。
{
"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": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}