icn*_*icn 6 c++ unordered-map hashtable
我在Ubuntu中使用g ++
g ++(Ubuntu 4.4.3-4ubuntu5)4.4.3
我有这个代码
#include<unordered_map>
using namespace std;
bool ifunique(char *s){
unordered_map<char,bool> h;
if(s== NULL){
return true;
}
while(*s){
if(h.find(*s) != h.end()){
return false;
}
h.insert(*s,true);
s++;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
当我编译使用
g++ mycode.cc
Run Code Online (Sandbox Code Playgroud)
我收到了错误
error: 'unordered_map' was not declared in this scope
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
Hug*_*ugh 19
如果您不想在C++ 0x模式下编译,请将include和using指令更改为
#include <tr1/unordered_map>
using namespace std::tr1;
Run Code Online (Sandbox Code Playgroud)
应该管用
wkl*_*wkl 12
在GCC 4.4.x中,您只需要#include <unordered_map>,并使用以下行编译:
g++ -std=c++0x source.cxx
有关GCC中C++ 0x支持的更多信息.
编辑你的问题
std::make_pair<char, bool>(*s, true)插入时必须要做.
此外,您的代码只会插入一个字符(解除引用*s).您打算使用单个char键作为键,还是意味着存储字符串?