C ++: problems assembling stl hash file

The following example won't compile for me:

#include <iostream>
#include <functional>
#include <string>

int main()
{
  std::string str = "Meet the new boss...";
  std::hash<std::string> hash_fn;
  size_t str_hash = hash_fn(str);

  std::cout << str_hash << '\n';
}

      

I am getting the following output from g ++

> g++ -o test test.cpp 
test.cpp: In functionint main()’:
test.cpp:8: error: ‘hashis not a member ofstdtest.cpp:8: error: expected primary-expression before ‘>’ token
test.cpp:8: error: ‘hash_fnwas not declared in this scope

      

Am I missing a compile flag or something else?

Additional Information:

> g++ -v
Using built-in specs.
Target: i686-apple-darwin10
Configured with: /var/tmp/gcc/gcc-5666.3~6/src/configure --disable-checking --enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin10 --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10 --with-gxx-include-dir=/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5666) (dot 3)

> uname -a
Darwin ############# 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun  7 16:33:36 PDT 2011; ro

      

+3


source to share


1 answer


found the answer here

this code compiles:



#include <iostream>
#include <tr1/functional>
#include <string>

int main()
{
  double d = 3;
  std::tr1::hash<double> hash_fn;
  size_t str_hash = hash_fn(d);

  std::cout << str_hash << '\n';
}

      

+7


source







All Articles