我正在使用 android NDK r9d 和工具链 4.8,但我无法使用 std::to_string 函数,编译器会抛出此错误:
error: 'to_string' is not a member of 'std'
android ndk不支持这个功能吗?我尝试APP_CPPFLAGS := -std=c++11
没有运气。
你可以试试LOCAL_CFLAGS := -std=c++11
,但请注意并非所有 C++11 API 都可用于 NDK 的 gnustl https://stackoverflow.com/questions/17950814/how-to-use-stdstoul-and-stdstoull-in-android/18124627#18124627。 libc++ 提供完整的 C++14 支持(APP_STL := c++_shared
).
另一种方法是自己实施。
#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) ;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)