c++c++11char16-t

C++11 char16_t strstr and sprintf equivalent


Is there any equivalent function to strstr and sprintf for char16_t type?

Also, where could I find the remaining functions of char16_t?


Solution

  • I don't think there are such functions.

    If sizeof(char16_t) == sizeof(wchar_t) you could use the wide string functions like wsprintf

    Caveat: sizeof(wchar_t) == sizeof(int32_t) on Linux!

    And you can always use (in C++11) the std::u16string

    Perhaps you might consider using Qt5 QChar (almost like a char16_t in UTF16) and QString. You'll only need to link QtCore for that. Then QString::arg is similar (but not equivalent) to what sprintf can offer.

    As I commented, float to string conversion is tricky. Perhaps some code from MUSL libc (free software, MIT license) could inspire you, and you might borrow some of it.