7

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

何か不足していますか?

4

2 に答える 2

21

C++0x モードでコンパイルしたくない場合は、include および using ディレクティブを次のように変更します。

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

動作するはずです

于 2010-10-19T23:54:07.903 に答える
15

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か、それとも文字列を格納するつもりでしたか?

于 2010-10-19T23:41:15.517 に答える