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
Am I missing something?
In GCC 4.4.x, you should only have to
#include <unordered_map>, and compile with this line:g++ -std=c++0x source.cxxMore 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 singlecharfor a key, or did you mean to store strings?