Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/158.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
wcstombs()在Android上的输出无效_Android_C++_Android Ndk_Libc - Fatal编程技术网

wcstombs()在Android上的输出无效

wcstombs()在Android上的输出无效,android,c++,android-ndk,libc,Android,C++,Android Ndk,Libc,我正在尝试将一些旧的C/C++代码移植到NDK的最新版本,但我正在努力使用wcstombs函数。这个函数在Android上返回wierd结果,我不知道为什么 查看这个代码,这是从C++引用的例子中的例子 const wchar_t str[] = L"wcstombs example"; char buffer[32]; int ret; ret = wcstombs ( buffer, str, sizeof(buffer) ); if (ret==32) buffer[

我正在尝试将一些旧的C/C++代码移植到NDK的最新版本,但我正在努力使用wcstombs函数。这个函数在Android上返回wierd结果,我不知道为什么

查看这个代码,这是从C++引用的例子中的例子

  const wchar_t str[] = L"wcstombs example";
  char buffer[32];
  int ret;

  ret = wcstombs ( buffer, str, sizeof(buffer) );
  if (ret==32) buffer[31]='\0';

  __android_log_print(ANDROID_LOG_WARN, "dbg", "%d ... %s", ret, buffer);


// Application.mk
APP_ABI := armeabi-v7a
APP_STL := gnustl_static
APP_PLATFORM := android-19
此代码打印2。。。W如果从字符串中读取一个零字节,则函数看起来会停止

这正常吗?这个功能是否有替代品

Thx.

您可以使用

snprintf(buffer, sizeof(buffer), "%ls", str);
你可以用

snprintf(buffer, sizeof(buffer), "%ls", str);

我终于找到了这个问题的解决办法。应用程序必须链接到LLVM libc++而不是GNU STL。 Application.mk应如下所示:

APP_ABI := armeabi-v7a
APP_STL := c++_static
APP_PLATFORM := android-19

我终于找到了这个问题的解决办法。应用程序必须链接到LLVM libc++而不是GNU STL。 Application.mk应如下所示:

APP_ABI := armeabi-v7a
APP_STL := c++_static
APP_PLATFORM := android-19

我也有同样的问题。更改STL库对我不起作用

但是,使用此实现确实有效

还有crystax ndk,它是google ndk的替代品。这可能是有用的


我也有同样的问题。更改STL库对我不起作用

但是,使用此实现确实有效

还有crystax ndk,它是google ndk的替代品。这可能是有用的


snprintf不是wcstombs的替代品。您可以将NULL作为目标字符串传递给wcstombs,它应该返回组成转换字符串的字节数。所以您可以为转换后的字符串分配适当的内存。@zdenek您可以使用snprintf作为等效项,因为snprintf返回非截断字符串的长度。所以使用char-ch;int length=snprintf&ch,1,%ls,inputString;char*output_str=新字符[1+长度];snprintfoutput_str,1+长度,%ls,输入_str;根据我的经验,snprintf%ls与在NDK r10e上使用wctombs/wcsrtombs一样坏——这是有道理的,因为它们将使用相同的内部实现。snprintf不是wcstombs的替代品。您可以将NULL作为目标字符串传递给wcstombs,它应该返回组成转换字符串的字节数。所以您可以为转换后的字符串分配适当的内存。@zdenek您可以使用snprintf作为等效项,因为snprintf返回非截断字符串的长度。所以使用char-ch;int length=snprintf&ch,1,%ls,inputString;char*output_str=新字符[1+长度];snprintfoutput_str,1+长度,%ls,输入_str;在我的经验中,SNPRETNF %LS与使用NDK R10E上的WCCTMBOS/WCSRMUBS一样坏——这是有意义的,因为它们无论如何都会使用相同的内部实现。我想知道C++库如何改变解决与C函数相关的问题。我不知道如何改变C++库可以解决与C函数相关的问题。