我是C++新手,还在尝试在vscode中设置C/C++扩展。
我遵循了vscode官员提供的本教程:https://code.visualstudio.com/docs/cpp/config-clang-mac#_cc-configuration。
完成"lauch.json“、"tasks.json”和"c_cpp_properties.json“文件后,我单击了"play”图标,但调试器仍然会显示";“并打开launch.json文件。
我认为我在这篇文章中遇到了同样的问题,但它的解决方案未能解决我的问题:Mac VSCode Debugger always show error about ';' and ':'。
这是我的密码:
#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;
}这是我的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",
"type": "cppdbg",
"request": "launch",
"program": "enter program name, for example ${workspaceFolder}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
}
]
}这是我的tasks.json文件:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}这是我的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
}谢谢!
发布于 2022-06-04 02:04:56
问题是program字段在launch.json中不正确,如果您的CPP名称是your-program.cpp,则可以将program字段设置为your-program。
因为编译输出文件名是"${fileDirname}/${fileBasenameNoExtension}",正如您在tasks.json中设置的那样
{
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "your-program", // set it to right name.
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
}
]
}https://stackoverflow.com/questions/72491400
复制相似问题