#include <bits/stdc++.h>
int main()
{
std::unordered_map<int, int> test{};
test[2] = 14;
std::cout << test[2];
}
错误:
我在 Ubuntu Linux 上的 VS Code C++ 中测试了代码,但无法编译它(它在在线编译器中运行良好)。为什么会出现这些错误以及如何修复它们?
第一个,在你的评论中你说“在编译器中它可以工作”,但在 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];
}