我在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;
}

当我编译时

g++ mycode.cc

我有错误

 error: 'unordered_map' was not declared in this scope

我想念什么吗?

有帮助吗?

解决方案

在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 对于钥匙,还是您的意思是存放字符串?

其他提示

如果您不想以C ++ 0x模式进行编译,请将Inclubel和使用指令更改为

#include <tr1/unordered_map>
using namespace std::tr1;

应该管用

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top