Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 接收错误:使用未声明的标识符'__stl#U哈希#U字符串';{return uu stl_hash_string(uu s.c_str());}_C++_Macos_Osx Mountain Lion_Xcode4.6 - Fatal编程技术网

C++ 接收错误:使用未声明的标识符'__stl#U哈希#U字符串';{return uu stl_hash_string(uu s.c_str());}

C++ 接收错误:使用未声明的标识符'__stl#U哈希#U字符串';{return uu stl_hash_string(uu s.c_str());},c++,macos,osx-mountain-lion,xcode4.6,C++,Macos,Osx Mountain Lion,Xcode4.6,我收到一个错误 error: use of undeclared identifier '__stl_hash_string' { return __stl_hash_string( __s.c_str() ); } 在Mac OS 10.8上使用Xcode 4.6.1编译时 /------下面的代码片段----/ 在第二行告诉我无法包含此标题时出错。我不确定这个方法在新环境中是否被弃用,如果它被弃用了,那么替代方法是什么。我请求您帮助解决这个问题。看起

我收到一个错误

error: use of undeclared identifier '__stl_hash_string'
                    { return __stl_hash_string( __s.c_str() ); }
在Mac OS 10.8上使用Xcode 4.6.1编译时

/------下面的代码片段----/


在第二行告诉我无法包含此标题时出错。我不确定这个方法在新环境中是否被弃用,如果它被弃用了,那么替代方法是什么。我请求您帮助解决这个问题。

看起来像libstdc++中定义的函数。这个库在Xcode 3.5中是默认的,现在Xcode默认使用libc++。但是您仍然可以在
C++标准库
build设置中将其切换到libstdc++
但是,如果您可以在项目中使用C++11,我建议您使用标准函数fo string,而不要依赖内部std函数。

看起来像libstdc++中定义的函数。这个库在Xcode 3.5中是默认的,现在Xcode默认使用libc++。但是您仍然可以在
C++标准库
build设置中将其切换到libstdc++
但是,如果您可以在项目中使用C++11,我建议您使用标准函数fo string,而不要依赖内部std函数。

我已经修改了头文件,以便在使用libc++时不使用此哈希支持定义

/

/---------------------------------------------------------------------------
//•哈希函数支持
// ---------------------------------------------------------------------------
#ifdef_LIBCPP_版本
/*std::hash在libc++中可用,因此不需要hash支持*/
#埃利夫
名称空间
{
模板
结构散列
{
size\u t运算符()(常量std::string&\u s)常量
{return uu stl_hash_string(uu s.c_str());}
};
}
#恩迪夫

谢谢科迪的回答。现在它编译得很好。但是添加“/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer”/‌​sdk/MacOSX10.8.sdk/usr/include/c++/4.2.1/没有帮助,因为许多产品都共享此代码。因此无法放置绝对头路径

我修改了头文件,在使用libc++时不使用此哈希支持定义

I have modified the code again so that there won't be any issues for any other clients using this header for the hash functionality.

// ---------------------------------------------------------------------------
//  • hash function support
// ---------------------------------------------------------------------------
//
#ifdef _LIBCPP_VERSION
    template<>
    struct hash<std::string>
    {
        size_t operator()(const std::string& __s) const
        {
            std::hash<std::string> hash_fn;
            return hash_fn(__s);
        }
    };
#elif __cplusplus

    namespace __gnu_cxx
    {
        template<>
        struct hash<std::string>
        {
            size_t operator()(const std::string& __s) const
            { return __stl_hash_string( __s.c_str() ); }
        };
    }
#endif
/

/---------------------------------------------------------------------------
//•哈希函数支持
// ---------------------------------------------------------------------------
#ifdef_LIBCPP_版本
/*std::hash在libc++中可用,因此不需要hash支持*/
#埃利夫
名称空间
{
模板
结构散列
{
size\u t运算符()(常量std::string&\u s)常量
{return uu stl_hash_string(uu s.c_str());}
};
}
#恩迪夫
谢谢科迪的回答。现在它编译得很好。但是添加“/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer”/‌​sdk/MacOSX10.8.sdk/usr/include/c++/4.2.1/没有帮助,因为许多产品都共享此代码。因此无法放置绝对头路径

我再次修改了代码,以便使用此头的哈希功能的任何其他客户端都不会出现任何问题。
I have modified the code again so that there won't be any issues for any other clients using this header for the hash functionality.

// ---------------------------------------------------------------------------
//  • hash function support
// ---------------------------------------------------------------------------
//
#ifdef _LIBCPP_VERSION
    template<>
    struct hash<std::string>
    {
        size_t operator()(const std::string& __s) const
        {
            std::hash<std::string> hash_fn;
            return hash_fn(__s);
        }
    };
#elif __cplusplus

    namespace __gnu_cxx
    {
        template<>
        struct hash<std::string>
        {
            size_t operator()(const std::string& __s) const
            { return __stl_hash_string( __s.c_str() ); }
        };
    }
#endif
// --------------------------------------------------------------------------- //•哈希函数支持 // --------------------------------------------------------------------------- // #ifdef_LIBCPP_版本 模板 结构散列 { size\u t运算符()(常量std::string&\u s)常量 { std::hash散列\u fn; 返回散列函数fn(u_s); } }; #埃利夫 名称空间 { 模板 结构散列 { size\u t运算符()(常量std::string&\u s)常量 {return uu stl_hash_string(uu s.c_str());} }; } #恩迪夫
我再次修改了代码,以便使用此头的哈希功能的任何其他客户端都不会出现任何问题。
// ---------------------------------------------------------------------------
//•哈希函数支持
// ---------------------------------------------------------------------------
//
#ifdef_LIBCPP_版本
模板
结构散列
{
size\u t运算符()(常量std::string&\u s)常量
{
std::hash散列\u fn;
返回散列函数fn(u_s);
}
};
#埃利夫
名称空间
{
模板
结构散列
{
size\u t运算符()(常量std::string&\u s)常量
{return uu stl_hash_string(uu s.c_str());}
};
}
#恩迪夫

感谢您的回复,是的,我们使用的是libc++CXX=clang++cxflags='-stdlib=libc++'你知道stl\u hash\u string的等效std::hash函数吗?也许你应该尝试将'/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/sdk/MacOSX10.8.sdk/usr/include/c++/4.2.1/'路径添加到头搜索路径?没关系,这个答案是在你编辑之前为你的评论写的。你使用C++11吗?如果是这样,您不需要任何手工制作的哈希函数,它们都已经存在。感谢您的回复,是的,我们使用的是libc++CXX=clang++cxflags='-stdlib=libc++'你知道stl\u hash\u string的等效std::hash函数吗?也许你应该尝试将'/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/sdk/MacOSX10.8.sdk/usr/include/c++/4.2.1/'路径添加到头搜索路径?没关系,这个答案是在你编辑之前为你的评论写的。你使用C++11吗?如果是这样,您不需要任何手工制作的哈希函数,它们都已经存在。
/ ---------------------------------------------------------------------------
//      • hash function support
// ---------------------------------------------------------------------------
#ifdef _LIBCPP_VERSION
        /*std::hash available in libc++ so no hash support required*/
#elif __cplusplus
        namespace __gnu_cxx
        {
                template<>
                struct hash<std::string>
                {
                        size_t operator()(const std::string& __s) const
                        { return __stl_hash_string( __s.c_str() ); }
                };
        }
#endif
I have modified the code again so that there won't be any issues for any other clients using this header for the hash functionality.

// ---------------------------------------------------------------------------
//  • hash function support
// ---------------------------------------------------------------------------
//
#ifdef _LIBCPP_VERSION
    template<>
    struct hash<std::string>
    {
        size_t operator()(const std::string& __s) const
        {
            std::hash<std::string> hash_fn;
            return hash_fn(__s);
        }
    };
#elif __cplusplus

    namespace __gnu_cxx
    {
        template<>
        struct hash<std::string>
        {
            size_t operator()(const std::string& __s) const
            { return __stl_hash_string( __s.c_str() ); }
        };
    }
#endif