C ++ unordered_map compiling problems with g ++

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 compiling using

 g++ mycode.cc 

I got an error

  error: 'unordered_map' was not declared in this scope 

Did I miss something?

+6
c ++ hashtable unordered-map
source share
2 answers

In GCC 4.4.x, you only need #include <unordered_map> and compile this line:

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

Additional Information on C ++ 0x Support in GCC .

change your problem

You should do std::make_pair<char, bool>(*s, true) when pasting.

In addition, your code will only insert one character (dereferencing via *s ). Do you intend to use a single char key for the key, or do you want to save strings?

+9
source share

If you do not want to compile in C ++ 0x mode, change the include and using directive to

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

must work

+19
source share

All Articles