Search code examples
c++booststdstringboost-interprocess

Convert boost::container::boost basic_string to std::string


Is there a simple way to do this? I've tried the following:

typedef allocator<char,managed_shared_memory::segment_manager>
    CharAllocator;
typedef boost::container::basic_string<char, std::char_traits<char>, CharAllocator>
    my_basic_string;

std::string s(my_basic_string);

Solution

  • As @T.C. has said, you should use:

    std::string s(my_basic_string.data(), my_basic_string.size());
    

    or

    std::string s(my_basic_string.begin(), my_basic_string.end());
    

    I prefer the second, but both will work.