Visual Studio Code 在编译“_zst28__ throw_bad_array_new_lengthv”时无法识别 std 库

发布于 2025-01-09 07:38:52 字数 1656 浏览 2 评论 0原文

所以基本上我遵循的是使用 Visual Studio Code 设置 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 << " ";
    }
    cout << endl;
}

编辑 当我编译代码时,会正确生成 .exe 文件。但是,当我尝试运行编译程序 我弹出以下错误。。当我尝试从 VSCode 终端运行它时,我没有收到错误 "_zst28__ throw_bad_array_new_lengthv", 它只是得到不执行任何操作就执行 这是我的 task.json 配置。我不确定我在设置时哪里出错了。代码可以编译,但无法运行。

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe compilar archivo activo",
            "command": "C:\\msys64\\mingw64\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "compilador: C:\\msys64\\mingw64\\bin\\g++.exe"
        }
    ]
}

So basically I was following the official documentation of setting up C++ with Visual Studio Code. So I followed every step and copied their code:

#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 << " ";
    }
    cout << endl;
}

EDIT When I compile the code an .exe file is generated correctly. However, when I try to run the compile programme I get the following mistake as popup.. When I try to run it from my VSCode terminal I don't get that mistake "_zst28__throw_bad_array_new_lengthv", it just gets executed without doing anything
This is my task.json configuration. I am not sure where I made a mistake while setting up. The code compiles, but it does not run.

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe compilar archivo activo",
            "command": "C:\\msys64\\mingw64\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "compilador: C:\\msys64\\mingw64\\bin\\g++.exe"
        }
    ]
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文