简体   繁体   中英

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?

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.

For strstr you can use std::u16string_view::find or even the C++23 std::u16string_view::contains if you're only interested in a boolean result.

const bool contains_world =
    std::u16string_view(u"Hello, World!").find(u"World") != std::u16string_view::npos;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM