如何使用std :: stoul和std :: stoull在Android中? [英] How to use std::stoul and std::stoull in Android?
问题描述
C ++ 11有两个新的字符串转换函数为无符号长
和很长很长
:的std :: stoul()
和的std ::斯托尔()
。
C++11 has two new string conversion functions into unsigned long
and long long
: std::stoul()
and std::stoll()
.
近期的Android NDK R9介绍锵3.3编译器被认为是C ++ 11功能齐全。有这些函数的原型内心深处NDK,不过,我可以不使用它们。
The recent Android NDK r9 introduces Clang 3.3 compiler which is said to be C++11 feature complete. There are prototypes for these functions deep inside NDK, however I cannot use them.
什么我需要做的,使用他们?
What do I need to do to use them?
PS 我已经做 LOCAL_CPPFLAGS + = -std = C ++ 11
推荐答案
为什么你不能使用的功能的原因很根深蒂固的,可惜目前无法解决的。
The reason why you cannot use the functions is quite deep rooted, and unfortunately currently unsolvable.
展望库/ armeabi-V7A /包括/位/ C ++的config.h
在GNU stdlibc ++文件夹中的文件,你会看到这一点:
Looking into the libs/armeabi-v7a/include/bits/c++config.h
file in the gnu stdlibc++ folder, you'll see this:
...
/* Define if C99 functions or macros from <wchar.h>, <math.h>, <complex.h>,
<stdio.h>, and <stdlib.h> can be used or exposed. */
/* #undef _GLIBCXX_USE_C99 */
...
以上,与下面的代码片段一起从位/ basic_string.h
法术坏消息:
...
#if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99) \
&& !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
/* The definitions of Numeric Conversions [string.conversions] */
#endif
...
因此,这些功能都无法使用的NDK。
Thus, these functions are unusable in the NDK.
根本原因:的根本原因似乎是对C99功能的使用已经在armeabi-V7A平台上的GNU stdlibc ++被禁用由于这样的事实的仿生libc中不支持复杂的数学(在Android标准C库是仿生)。
Root Cause: The root cause seems to be that the C99 functionality usage has been disabled in the GNU stdlibc++ on the armeabi-v7a platform due to the fact the the Bionic libc does not support complex math (the standard C library on Android is Bionic).
可能修复(未测试):探索 CrystaX的Android NDK 似乎有扩展在香草的Android NDK。
Possible Fix (untested): Explore CrystaX's Android NDK which seems to have extensions over the Vanilla Android NDK.
注意: __ GXX_EXPERIMENTAL_CXX0X __
通过添加定义 -std = GNU + 11
以 APP_CXXFLAGS
或 LOCAL_CXXFLAGS
Note: __GXX_EXPERIMENTAL_CXX0X__
is defined by adding -std=gnu++11
to APP_CXXFLAGS
or LOCAL_CXXFLAGS
详细的测试日志:内置使用NDK版本R8E
JNI / Application.mk 的:
Detailed Test log: Built using NDK version r8e
jni/Application.mk:
APP_STL := gnustl_static
APP_CXXFLAGS += -std=gnu++11
NDK_TOOLCHAIN_VERSION := 4.7
JNI / Android.mk 的
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := cxx11
LOCAL_SRC_FILES := cxx11.cpp
include $(BUILD_EXECUTABLE)
JNI / cxx11.cpp 的:
#include <iostream>
#include <string>
int main(int argc, char* argv[]) {
#if defined(__GXX_EXPERIMENTAL_CXX0X__)
std::cout<<"__GXX_EXPERIMENTAL_CXX0X__ defined."<<std::endl;
#else
std::cout<<"__GXX_EXPERIMENTAL_CXX0X__ not defined."<<std::endl;
#endif
#if defined(_GLIBCXX_USE_C99)
std::cout<<"_GLIBCXX_USE_C99 defined."<<std::endl;
#else
std::cout<<"_GLIBCXX_USE_C99 not defined."<<std::endl;
#endif
#if defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)
std::cout<<"_GLIBCXX_HAVE_BROKEN_VSWPRINTF defined."<<std::endl;
#else
std::cout<<"_GLIBCXX_HAVE_BROKEN_VSWPRINTF not defined."<<std::endl;
#endif
#if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99) \
&& !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
std::string s="1";
std::cout<<"ll:"<<std::stoll(s)<<std::endl<<"ul:"<<std::stoul(s)<<std::endl;
#else
std::cout<<"No support for stoll/stoul."<<std::endl;
#endif
return(0);
}
输出在Nexus 4(安卓4.3):
Output on Nexus 4 (Android 4.3):
u0_a51@mako:/ $ /data/local/tmp/cxx11
__GXX_EXPERIMENTAL_CXX0X__ defined.
_GLIBCXX_USE_C99 not defined.
_GLIBCXX_HAVE_BROKEN_VSWPRINTF not defined.
No support for stoll/stoul.
这篇关于如何使用std :: stoul和std :: stoull在Android中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!