Android ndk std::to_string 支持 [英] Android ndk std::to_string support
问题描述
我正在使用 android NDK r9d 和 toolchain 4.8 但我无法使用 std::to_string 函数,编译器抛出此错误:
I'm using android NDK r9d and toolchain 4.8 but I'm not able to use std::to_string function, compiler throws this error:
error: 'to_string' is not a member of 'std'
android ndk 不支持这个功能吗?我尝试 APP_CPPFLAGS := -std=c++11
没有运气.
Is this function not supported on android ndk? I try APP_CPPFLAGS := -std=c++11
with no luck.
推荐答案
你可以试试LOCAL_CFLAGS := -std=c++11
,但是注意并非所有 C++11 API 都可用于 NDK 的 gnustl.libc++ (APP_STL := c++_shared
) 提供完整的 C++14 支持.
You can try LOCAL_CFLAGS := -std=c++11
, but note that not all C++11 APIs are available with the NDK's gnustl. Full C++14 support is available with libc++ (APP_STL := c++_shared
).
另一种方法是自己实现.
The alternative is to implement it yourself.
#include <string>
#include <sstream>
template <typename T>
std::string to_string(T value)
{
std::ostringstream os ;
os << value ;
return os.str() ;
}
int main()
{
std::string perfect = to_string(5) ;
}
这篇关于Android ndk std::to_string 支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!