Converting std::__cxx11::string to std::string(将 std::__cxx11::string 转换为 std::string)
问题描述
我用的是c++11,但也有一些库没有为它配置,需要一些类型转换.特别是我需要一种将 std::__cxx11::string
转换为常规 std::string
的方法,但是谷歌搜索我找不到这样做的方法并把前面的(string)
不起作用.
I use c++11, but also some libraries that are not configured for it, and need some type conversion. In particular I need a way to convert std::__cxx11::string
to regular std::string
, but googling I can't find a way to do this and putting (string)
in front does not work.
如果我不转换,我会收到这样的链接器错误:
If I do not convert I get linker errors like this:
undefined reference to `H5::CompType::insertMember(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long, H5::DataType const&) const'
推荐答案
您是否可能使用 GCC 5?
Is it possible that you are using GCC 5?
如果您收到有关未定义引用符号的链接器错误,这些符号涉及 std::__cxx11 命名空间或标记 [abi:cxx11] 中的类型,那么这可能表明您正在尝试将使用不同值编译的目标文件链接在一起对于 _GLIBCXX_USE_CXX11_ABI 宏.当链接到使用旧版 GCC 编译的第三方库时,通常会发生这种情况.如果无法使用新 ABI 重建第三方库,则需要使用旧 ABI 重新编译代码.
If you get linker errors about undefined references to symbols that involve types in the std::__cxx11 namespace or the tag [abi:cxx11] then it probably indicates that you are trying to link together object files that were compiled with different values for the _GLIBCXX_USE_CXX11_ABI macro. This commonly happens when linking to a third-party library that was compiled with an older version of GCC. If the third-party library cannot be rebuilt with the new ABI then you will need to recompile your code with the old ABI.
来源:GCC 5 发行说明/双 ABI
定义以下宏之前包括任何标准库头应该可以解决您的问题:#define _GLIBCXX_USE_CXX11_ABI 0
Defining the following macro before including any standard library headers should fix your problem: #define _GLIBCXX_USE_CXX11_ABI 0
这篇关于将 std::__cxx11::string 转换为 std::string的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 std::__cxx11::string 转换为 std::string


基础教程推荐
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01
- C++,'if' 表达式中的变量声明 2021-01-01
- 设计字符串本地化的最佳方法 2022-01-01
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17
- 运算符重载的基本规则和习语是什么? 2022-10-31
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01