C++ c++;:stl哈希编译问题
以下示例不会为我编译:C++ c++;:stl哈希编译问题,c++,macos,stl,compiler-errors,g++,C++,Macos,Stl,Compiler Errors,G++,以下示例不会为我编译: #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_ha
#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';
}
我是否缺少编译标志或什么
相关信息:
> 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
找到了答案
此代码编译:
#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';
}
#包括
#包括
#包括
int main()
{
双d=3;
std::tr1::散列\u fn;
大小\u t str\u hash=hash\u fn(d);
std::cout尝试使用-std=c++0x
标志,我认为std::hash
是c++11的一部分,不是吗?不,cc1plus:error:unrecogned命令行选项“-std=c++0x”
我想我得到了它(见下文)似乎是mac特有的名称空间问题,感谢您的帮助:)如果您使用macports,您可以在mac上安装GCC4.6。
#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';
}