提问人:Mini-Touch 提问时间:9/2/2023 最后编辑:ks1322Mini-Touch 更新时间:9/2/2023 访问量:85
错误:显示“class std::unordered_map<int, char> 没有名为”contains“的成员
Error: It shows 'class std::unordered_map<int, char>' has no member named 'contains'
问:
我最近一直在学习地图的功能。当我尝试使用包含时,它一直显示错误。代码如下:
#include <iostream>
#include <unordered_map>
using namespace std;
int main()
{
unordered_map<int, int> count = {{1, 5}, {2, 5}};
for (int i=1;i<=2;i++)
{
if (count.contains(i))
cout << i << ": Found\n";
else
cout << i << ": Not found\n";
}
}
我一直在寻找解决方案,我更新了 g++ 的版本并更改了 .json,但它不起作用。 g++ 的版本为 13.1.0 c_cpp_properties.json: “cppStandard”: “c++23”,
我不明白为什么它会出错。我错过了什么吗?这是我在这里的第一个问题。如果你觉得这个问题太傻了,请不要生气
答: 暂无答案
评论
c_cpp_properties.json
与运行编译器无关,它仅用于智能感知。您需要将实际选项传递给实际的编译器,可能是通过戳其他一些.配置 VSCode 可能很棘手。如果你想学习C++,我的建议是使用其他IDE,或者不使用IDE。.json
tasks.json
用于编译器。 用于智能感知。c_cpp_properties.json