VS Code C++ 中的“标识符“unordered_map”未定义”错误(在 Ubuntu Linux 上)

问题描述 投票:0回答:1
#include <bits/stdc++.h>

int main()
{
    std::unordered_map<int, int> test{};

    test[2] = 14;

    std::cout << test[2];
}

错误:

  • 标识符“unordered_map”未定义
  • 不允许输入类型名称
  • 标识符“test”未定义

我在 Ubuntu Linux 上的 VS Code C++ 中测试了代码,但无法编译它(它在在线编译器中运行良好)。为什么会出现这些错误以及如何修复它们?

c++ linux visual-studio-code c++11 unordered-map
1个回答
-1
投票

第一个,在你的评论中你说“在编译器中它可以工作”,但在 VS Code 中却不行。您使用的编译器可能支持 C++11 标准。确保 VS Code 配置为 C++11 或更高版本。在该链接中阅读如何:https://code.visualstudio.com/docs/cpp/config-linux

--

第二,我会修改包含部分:

#include <unordered_map> // Since C++11
#include <iostream>

int main()
{
    std::unordered_map<int, int> test{}; // (Since C++11)

    test[2] = 14;

    std::cout << test[2];
}

演示

© www.soinside.com 2019 - 2024. All rights reserved.