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++中已被棄用,爲什麼你不縮進你的代碼? –