Android: error: 'to_string' is not a member of 'std' NDK10c cocos 3.10v

Hello Guys,

I am trying to compile my app to Android, and getting always this error:
error: ā€˜to_stringā€™ is not a member of ā€˜stdā€™

My Aapplication.mk has:
APP_STL := gnustl_static

APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-char
APP_LDFLAGS := -latomic

Couldnā€™t fix with all solutions I found in internet,

Any help?

Hi TMSantos

I suggest you to use this super useful function:

cocos2d::StringUtils::format( ... )

It works like ā€œprintfā€ but instead of printing on stdout return a std::string! :slight_smile:

Iā€™m using solution found somewhere in the internet. I created to_string.h (and included it where needed) with following content:

#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#include <string>
#include <sstream>

namespace std
{
	template<typename T> std::string to_string(const T& t)
	{
		std::ostringstream os;
		os << t;
		return os.str();
	}
}    
#endif

Semiranis solution worked :smile:

Drakon99 somehow that method doesnt accept integers as argument.

Thank you guys !

@TMSantos you have to specify the format string to use: StringUtils::format("%d", 5);

See stevetranbyā€™s answer! :smile:

1 Like

Yeah, sorry for my stupidity for not looking carefull to the error xD

Both solutions works :slight_smile: thank you guys

1 Like