【发布时间】:2020-07-13 21:35:01
【问题描述】:
我正在尝试在我的 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;
}
并且错误信息显示
期待;在声明结束时 [9, 23] 预计 ;在声明结束时 [16, 23] 基于范围的 for 循环是 c++11 的扩展 [11, 29] 基于范围的 for 循环是 c++11 的扩展 [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
}
}
]
}
【问题讨论】:
-
请不要发布代码或错误消息的图像。请参阅this Meta post 了解众多原因的列表。代码和错误消息都是文本信息,应以该形式直接复制/粘贴到您的问题中。
-
你需要将 c++17 标志添加到 intellisense 编译器中(虽然我不能说如何在 VScode 中做到这一点)
-
我不确定你的意思。你能说得更详细一些吗?
-
这里解释了这个问题的解决方案stackoverflow.com/questions/55116344/…
标签: c++ c++11 visual-studio-code vscode-settings vscode-debugger