VSCode-有一条红色下划线,但程序构建和运行正确,并且出现了dubugging错误 我已经配置了我的VSCODE,在Linux上使用C++。最近我想编写一个新的cpp程序,我遵循了MS VScode教程,但当我将代码复制到VScode时,会出现一条红色下划线和如下提示:

VSCode-有一条红色下划线,但程序构建和运行正确,并且出现了dubugging错误 我已经配置了我的VSCODE,在Linux上使用C++。最近我想编写一个新的cpp程序,我遵循了MS VScode教程,但当我将代码复制到VScode时,会出现一条红色下划线和如下提示: ,c++,visual-studio-code,C++,Visual Studio Code,但是,我可以构建它,甚至可以无误地正确运行它: 当我调试它时,会发生错误 { "resource": "/home/aqachun/Documents/Projects/cpp/vscodeTest/helloworld.cpp", "owner": "C/C++", "severity": 8, "message": "no instance of constructor \"std::vector<_Tp, _Alloc>::vector [wit

但是,我可以构建它,甚至可以无误地正确运行它:

当我调试它时,会发生错误

{
    "resource": "/home/aqachun/Documents/Projects/cpp/vscodeTest/helloworld.cpp",
    "owner": "C/C++",
    "severity": 8,
    "message": "no instance of constructor \"std::vector<_Tp, _Alloc>::vector [with _Tp=std::string, _Alloc=std::allocator<std::string>]\" matches the argument list -- argument types are: (const char [6], const char [4], const char [6], const char [5], const char [8], const char [23])",
    "startLineNumber": 9,
    "startColumn": 24,
    "endLineNumber": 9,
    "endColumn": 24
}
我的代码是:

#包括
#包括
#包括
使用名称空间std;
int main()
{
向量MSG {“你好”、“C++”、“世界”、“来自”、“VS代码”、“和C++扩展”};
for(常量字符串和单词:msg)
{
cout我也做了那个教程(针对Linux),没有这样的错误。
这是我的c_cpp_properties.json文件,我想可能是因为您没有指定IntelliSense。请尝试我的c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Linux",
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "includePath": [
                "${default}",
                "/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../include/c++/9.2.0",
                "/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../include/c++/9.2.0/x86_64-pc-linux-gnu",
                "/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../include/c++/9.2.0/backward",
                "/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include",
                "/usr/local/include",
                "/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include-fixed",
                "/usr/include"
            ],
            "cppStandard": "c++17",
            "cStandard": "c11"
        }
    ],
    "version": 4
}
{
"configurations": [
    {
        "name": "Linux",
        "includePath": [
            "${workspaceFolder}/**"
        ],
        "defines": [],
        "compilerPath": "/usr/bin/gcc",
        "cStandard": "c11",
        "cppStandard": "c++17",
        "intelliSenseMode": "clang-x64"
    }
],
"version": 4
}

这是我的settings.json:

{
"files.associations": {
    "array": "cpp",
    "atomic": "cpp",
    "*.tcc": "cpp",
    "cctype": "cpp",
    "clocale": "cpp",
    "cmath": "cpp",
    "cstdarg": "cpp",
    "cstddef": "cpp",
    "cstdint": "cpp",
    "cstdio": "cpp",
    "cstdlib": "cpp",
    "cwchar": "cpp",
    "cwctype": "cpp",
    "deque": "cpp",
    "unordered_map": "cpp",
    "vector": "cpp",
    "exception": "cpp",
    "algorithm": "cpp",
    "memory": "cpp",
    "memory_resource": "cpp",
    "optional": "cpp",
    "string": "cpp",
    "string_view": "cpp",
    "system_error": "cpp",
    "tuple": "cpp",
    "type_traits": "cpp",
    "utility": "cpp",
    "fstream": "cpp",
    "initializer_list": "cpp",
    "iosfwd": "cpp",
    "iostream": "cpp",
    "istream": "cpp",
    "limits": "cpp",
    "new": "cpp",
    "ostream": "cpp",
    "sstream": "cpp",
    "stdexcept": "cpp",
    "streambuf": "cpp",
    "typeinfo": "cpp"
}
}

My 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": "g++ build and debug active file",
        "type": "cppdbg",
        "request": "launch",
        "program": "${fileDirname}/${fileBasenameNoExtension}",
        "args": [],
        "stopAtEntry": true,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ],
        "preLaunchTask": "g++ build active file",
        "miDebuggerPath": "/usr/bin/gdb"
    }
]
}

也许更改这些设置文件会有所帮助。我的工作

我也做了那个教程(针对Linux),没有这样的错误。 这是我的c_cpp_properties.json文件,我想可能是因为您没有指定IntelliSense。试试我的c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Linux",
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "includePath": [
                "${default}",
                "/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../include/c++/9.2.0",
                "/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../include/c++/9.2.0/x86_64-pc-linux-gnu",
                "/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../include/c++/9.2.0/backward",
                "/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include",
                "/usr/local/include",
                "/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include-fixed",
                "/usr/include"
            ],
            "cppStandard": "c++17",
            "cStandard": "c11"
        }
    ],
    "version": 4
}
{
"configurations": [
    {
        "name": "Linux",
        "includePath": [
            "${workspaceFolder}/**"
        ],
        "defines": [],
        "compilerPath": "/usr/bin/gcc",
        "cStandard": "c11",
        "cppStandard": "c++17",
        "intelliSenseMode": "clang-x64"
    }
],
"version": 4
}

这是我的settings.json:

{
"files.associations": {
    "array": "cpp",
    "atomic": "cpp",
    "*.tcc": "cpp",
    "cctype": "cpp",
    "clocale": "cpp",
    "cmath": "cpp",
    "cstdarg": "cpp",
    "cstddef": "cpp",
    "cstdint": "cpp",
    "cstdio": "cpp",
    "cstdlib": "cpp",
    "cwchar": "cpp",
    "cwctype": "cpp",
    "deque": "cpp",
    "unordered_map": "cpp",
    "vector": "cpp",
    "exception": "cpp",
    "algorithm": "cpp",
    "memory": "cpp",
    "memory_resource": "cpp",
    "optional": "cpp",
    "string": "cpp",
    "string_view": "cpp",
    "system_error": "cpp",
    "tuple": "cpp",
    "type_traits": "cpp",
    "utility": "cpp",
    "fstream": "cpp",
    "initializer_list": "cpp",
    "iosfwd": "cpp",
    "iostream": "cpp",
    "istream": "cpp",
    "limits": "cpp",
    "new": "cpp",
    "ostream": "cpp",
    "sstream": "cpp",
    "stdexcept": "cpp",
    "streambuf": "cpp",
    "typeinfo": "cpp"
}
}

My 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": "g++ build and debug active file",
        "type": "cppdbg",
        "request": "launch",
        "program": "${fileDirname}/${fileBasenameNoExtension}",
        "args": [],
        "stopAtEntry": true,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ],
        "preLaunchTask": "g++ build active file",
        "miDebuggerPath": "/usr/bin/gdb"
    }
]
}


也许更改这些设置文件会有所帮助。我的工作

看起来像是一个智能感知错误。这个错误实际上是一个构建失败,所以你声称你可以构建肯定是一个误解。至少我是这么想的。如果你描述你所做的和你所观察到的,人们可以给出更好的诊断。作为一个新用户,也请阅读。@UlrichEckhardt谢谢,我已经用两张关于运行构建任务和运行程序的图片更新了我的问题,它似乎运行得很好吗?有趣的是,这对我来说很好,使用clang++-9I,我在VSCode中也没有收到类似intellisense错误的错误。该错误实际上是一个构建失败,所以你所说的你可以构建一定是一种误解。至少我是这么想的。如果你描述你所做的和你所观察到的,人们可以给出更好的诊断。作为一个新用户,也请阅读。@UlrichEckhardt谢谢,我已经用两张关于运行构建任务和运行程序的图片更新了我的问题,它似乎运行得很好吗?有趣的是,这对我来说很好,使用clang++-9I我在VSCode中也没有这样的错误谢谢,我尝试将
“intelliSenseMode”
设置为
“clang-x64”
,但是错误仍然存在。然后我将我的
“includePath”
更改为
“${workspaceFolder}/**”
,我得到一个
#include检测到的错误。请更新您的includePath,当单击灯泡以添加其所说要添加的includePath时,再次显示原始错误。也许我应该配置我的c/cpp扩展?检查你是否有clang(你可以很容易地在Linux上安装它)只要转到
哪里有clang
如果你安装了它,如果不转到
sudo apt get install clang
,就会出现它的路径。您可以使用clang,它是一个普通的、好的编译器。另外,请确保已安装启用IntelliSense的扩展。谢谢,我尝试将
“intelliSenseMode”
设置为
“clang-x64”
,但错误仍然存在。然后我将我的
“includePath”
更改为
“${workspaceFolder}/**”
,我得到一个
#include检测到的错误。请更新您的includePath,当单击灯泡以添加其所说要添加的includePath时,再次显示原始错误。也许我应该配置我的c/cpp扩展?检查你是否有clang(你可以很容易地在Linux上安装它)只要转到
哪里有clang
如果你安装了它,如果不转到
sudo apt get install clang
,就会出现它的路径。您可以使用clang,它是一个普通的、好的编译器。此外,请确保已安装启用IntelliSense的扩展