This code will give an error message "to_string was not declared in this scope"
#include <jni.h>
#inlcude <string>
#include <android/log.h>
using namespace std;
JNIEXPORT jboolean JNICALL Java_com_package_activity_method
(JNIEnv *env, jobject classObject,jdouble number) {
String string= to_string(number);
__android_log_print(ANDROID_LOG_DEBUG, "JNI","The number is: %s,string);
return;
}
if trace the header file I can find these in string.h -> basic_string.h
inline string
to_string(double __val)
{
const int __n =
__gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
"%f", __val);
}
So it was declared after all...
I can fix the problem by writing my own version of to_string
String to_string(double number){
std::stringstream ss;
ss << number;
return ss.str(); }
or change -DANDROID_STL to c++_static
but what I am trying to understand it which part of the code obscure the to_string method in gnustl from being seen.