Search code examples
c++stringwchar-t

Getting substring of wchar_t[]


I have:

wchar_t str[32];

I want to get a new substring of it, from place 0 to 5. How can I do it?


Solution

  • std::basic_string does have the constructor you're looking for:

    constexpr basic_string( const CharT* s,
                            size_type count,
                            const Allocator& alloc = Allocator() );
    

    So you may do:

    std::wstring substr{str, 5};