Home >Backend Development >C++ >How to Convert std::__cxx11::string to std::string in C 11?

How to Convert std::__cxx11::string to std::string in C 11?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-17 19:00:14756browse

How to Convert std::__cxx11::string to std::string in C  11?

Converting std::__cxx11::string to std::string

In C , when using C 11 alongside libraries not configured for the standard, type conversion becomes necessary. Specifically, converting std::__cxx11::string to std::string is often required.

Problem Statement:

Previously, attempts to perform this conversion using constructs like (string) have failed, leading to linker errors similar to:

undefined reference to `H5::CompType::insertMember(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&amp;, unsigned long, H5::DataType const&amp;) const'

Solution:

This issue may arise when using GCC 5 and attempting to link object files compiled with different values for the _GLIBCXX_USE_CXX11_ABI macro. To resolve this, redefine the macro as follows:

#define _GLIBCXX_USE_CXX11_ABI 0

Place this definition before any inclusion of standard library headers in your code.

The above is the detailed content of How to Convert std::__cxx11::string to std::string in C 11?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn