l used ANDROID NDK 。so l want to format something。just use sprintf,but l can not use it with wchar_t. is there some helps for me?
相关问题
- Why is the C program giving weird output using Sca
- printf ptr: can the leading 0x be eliminated?
- format ’%s’ expects argument of type ’char *’
- Precision field in printf when formatting integer
- How do I make conditions in printf statements?
相关文章
- How can printf issue a compiler warning?
- Maximum size of string can be printed using %s?
- Is there any way to make visual C++ (9.0) generate
- print a cell array as .txt in Matlab
- Bash printf %q invalid directive
- How do I use sprintf to zero fill to a variable le
- how to get append mode in sprintf()
- In Perl, how can I limit the number of places afte
In Android OS NDK versions before 5.0 ("Lollipop"), the sprintf() does not support the "%ls" (wchar_t pointer) format specifier. Thus, the following statement compiles but does not execute correctly under NDK (pre-5.0):
The workaround is to convert the wchar_t string to UTF-8 (which is a char *) using any one of the Open Source wide-to-utf8 implementations (e.g. the UTF8-CPP project), passing its pointer to sprintf:
Starting with Android 5.0 ("Lollipop"), sprintf() supports the "%ls" format specifier, so the original sprintf() code above works correctly.
If your Android NDK code needs to run on all version of Android, you should wrap all your wchar_t pointers passed to sprintf with a macro like the following:
The GetSupportsSprintfWideChar() function should be a local function that returns true if the running Android OS is 5.0 or above, while returning false if the OS is pre-5.0.
You probably want swprintf and friends, assuming Android has it like Posix and Linux systems.
Glib (from GTK) has functions for unicode manipulation and for string utilities. I believe you should be able to make it work on Android.