g ++中内置unordered_map
概念是什么时候?GCC中的unordered_map错误
因为以下代码会引发错误。
#include<iostream>
#include<unordered_map>
#include<stdio.h>
using namespace std;
std::unordered_map<std::int,int> mirror;
mirror['A'] = 'A';
mirror['B'] = '#';
mirror['E'] = 3;
int main(void)
{
std::cout<<mirror['A'];
std::cout<<mirror['B'];
std::cout<<mirror['C'];
return 0;
}
我编译的代码如下:
g++ -c hashexample.cpp
g++ -o result hashExample.o
./result
我得到的错误是这样的:
inavalid类型int [字符[为aaray标
这是什么修复?
除了下面提供的解决方案,您可以考虑将您的模板从更改为,因为您仅使用字符来提供密钥。只是一个观察/建议! –
甚至不应该编译,因为'std :: int',这是无效的C++。 –
至少13年前,'stdio.h'在C++中已被弃用,为什么你不缩进你的代码? –