gpt4 book ai didi

c++ - Mac VSCode 调试器总是显示关于 ';' 和 ':' 的错误

转载 作者:行者123 更新时间:2023-12-03 07:03:48 25 4
gpt4 key购买 nike

我正在尝试在我的 Mac 上设置 vscode 环境。我按照网站上的程序https://code.visualstudio.com/docs/cpp/config-clang-mac
但是当我尝试调试我的程序时,它显示错误并且无法跳过。
我不确定是因为版本还是什么。

#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;
}

并且错误消息显示

expect ; at the end of declaration [9, 23] expect ; at the end of declaration [16, 23] range-based for loop is a c++11 extension [11, 29] range-based for loop is a c++11 extension [17, 29]



我的launch.json文件是
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
// "name": "(lldb) Launch",
"name": "clang++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "clang++ build active file"
}
]
}

我的 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++ - Mac VSCode 调试器总是显示关于 ';' 和 ':' 的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60982685/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com