日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

error: ‘to_string’ is not a member of ‘std’———已解决

發布時間:2025/3/13 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 error: ‘to_string’ is not a member of ‘std’———已解决 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

現象?

cocos2d-x 2.2.6 項目的源碼中使用了?std::to_string()?方法,使用 NDK r9d 編譯的時候,報如下錯誤:

error: 'to_string' is not a member of 'std'

Application.mk 文件的部分內容如下:

APP_STL := gnustl_static NDK_TOOLCHAIN_VERSION := 4.8 APP_CPPFLAGS := -frtti -std=c++11 -fexceptions -Wno-error=format-security -Wno-literal-suffix -Wno-deprecated-declarations -fsigned-char -Os $(CPPFLAGS)

換用 NDK 10e ,錯誤依然。

快速解決?

想快速解決這個問題,可以自己寫一個?std::to_string()?替換標準庫中的。

首先寫一個?stdtostring.h?文件:

#ifndef STDTOSTRING_H #define STDTOSTRING_H #include <string> #include <sstream>using namespace std; namespace std {template < typename T > std::string to_string( const T& n ){std::ostringstream stm ;stm << n ;return stm.str() ;} } #endif

然后在需要使用?std::to_stirng()?方法的源文件中包含它:

#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID #include "stdtostring.h" #endif

追根溯源?

Why gnustl_static?中介紹了采用?c++_static?和?clang?編譯器來實現std::to_string()?支持,于是我嘗試了下:

# APP_STL := gnustl_static # NDK_TOOLCHAIN_VERSION := 4.8 APP_STL := c++_static NDK_TOOLCHAIN_VERSION := clang

根據?C++ Library Support?的說明,?c++_static?對應的是 The LLVM libc++ runtime (static) ,因此應該采用 clang 的工具鏈進行編譯。

結果是:?std::to_string()?編譯正常,但出現下面的錯誤:

In file included from src/Utilities.cpp:1:0: android-ndk-r9d/sources/cxx-stl/llvm-libc++/libcxx/include/cmath:1498:46: error: expected unqualified-id before 'float' inline _LIBCPP_INLINE_VISIBILITY float remainder(float __x, float __y) _NOEXCEPT {return remainderf(__x, __y);}^ android-ndk-r9d/sources/cxx-stl/llvm-libc++/libcxx/include/cmath:1498:46: error: expected ')' before 'float' android-ndk-r9d/sources/cxx-stl/llvm-libc++/libcxx/include/cmath:1499:46: error: expected unqualified-id before 'long' inline _LIBCPP_INLINE_VISIBILITY long double remainder(long double __x, long double __y) _NOEXCEPT {return remainderl(__x, __y);}^ android-ndk-r9d/sources/cxx-stl/llvm-libc++/libcxx/include/cmath:1499:46: error: expected ')' before 'long' android-ndk-r9d/sources/cxx-stl/llvm-libc++/libcxx/include/cmath:1509:1: error: expected ')' before '__x' remainder(_A1 __x, _A2 __y) _NOEXCEPT ^ android-ndk-r9d/sources/cxx-stl/llvm-libc++/libcxx/include/cmath:1559:46: error: expected unqualified-id before 'float' inline _LIBCPP_INLINE_VISIBILITY float round(float __x) _NOEXCEPT {return roundf(__x);}^ android-ndk-r9d/sources/cxx-stl/llvm-libc++/libcxx/include/cmath:1559:46: error: expected ')' before 'float' android-ndk-r9d/sources/cxx-stl/llvm-libc++/libcxx/include/cmath:1560:46: error: expected unqualified-id before 'long' inline _LIBCPP_INLINE_VISIBILITY long double round(long double __x) _NOEXCEPT {return roundl(__x);}^ android-ndk-r9d/sources/cxx-stl/llvm-libc++/libcxx/include/cmath:1560:46: error: expected ')' before 'long' android-ndk-r9d/sources/cxx-stl/llvm-libc++/libcxx/include/cmath:1565:1: error: expected ')' before '__x' round(_A1 __x) _NOEXCEPT {return round((double)__x);}

minggo?在?Cocos can’t compile Android with APP_STL := c++_static?中提到:

A prebuilt version can only support one type of c++ lib. Did you mean we should provide two kinds of prebuilt libcocos2d that using two different c++ libs?

I don’t know if cocos2d can compile with c++_static or not. I don’t remember if there is a good reason to choose one instead of other one. But cocos2d-x uses gnustl_static from very early version, so we know it works well. You can replace it with c++_static if you like, but it is not fully tested.

因此我懷疑在 cocos2d-x 的舊版本中,?c++_static?是沒有經過完整測試的。

也有人說?在新版本(>3.7)中,?gnustl_static?會導致 lambda 和std::to_string?不能使用,已經切換到使用?c++_static?和 clange 組合。

I never made it to work with gnustl_static and gcc with all the c++11 features. I was getting crashes in simple lambdas, as mentioned std::to_string was missing and much more, so i’ve switched to c++_static and clang long time ago.

本文轉自:http://www.tuicool.com/articles/RBBjMz

轉載于:https://www.cnblogs.com/Anzhongliu/p/6091789.html

總結

以上是生活随笔為你收集整理的error: ‘to_string’ is not a member of ‘std’———已解决的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。