c++ unordered_map compiling issue with g++

Question:

I am using g++ in Ubuntu

g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3
I have this code

#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;
}
when I compile using

g++ mycode.cc
I got error

error: 'unordered_map' was not declared in this scope

Answer:

In GCC 4.4.x, you should only have to #include <unordered_map>, and compile with this line:

g++ -std=c++0x source.cxx

More information about C++0x support in GCC.

edit regarding your problem

You have to do std::make_pair<char, bool>(*s, true) when inserting.

Also, your code would only insert a single character (the dereferencing via *s). Do you intend to use a single char for a key, or did you mean to store strings?


你可能感兴趣的:(c++ unordered_map compiling issue with g++)