wcstombs()在Android上具有无效的输出 [英] wcstombs() has invalid output on Android

查看:223
本文介绍了wcstombs()在Android上具有无效的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



查看此代码(它是来自C ++参考的wcstombs()示例)

  const wchar_t str [] = Lwcstombs 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。它看起来像函数停止,如果它从字符串中读取一个零字节。



是否正常?

解决方案

这个函数有什么替代吗?



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

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


I'm trying to port some old C/C++ code to android(latest version of NDK), but I'm struggling with function wcstombs(). This function returns wierd result on Android and I don't know why.

Look at this code (it's wcstombs() example from C++ reference)

  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

This code prints "2 ... w". It looks like the function stops, if it reads a zero byte from the string.

Is it normal? Is there any replacement for this function?

Thx.

解决方案

I've finally found the solution to this problem. Application has to be linked against LLVM libc++ instead of GNU STL. Application.mk should look like this:

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

这篇关于wcstombs()在Android上具有无效的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆