[C++11] How to use std::stoi std::stod

3,920 views
Skip to first unread message

idea

unread,
Dec 1, 2014, 7:37:36 PM12/1/14
to andro...@googlegroups.com
Hello everyone.

Did anybody know how to use std::stoi and std::stod?
i always get error 'stol' is not a member of 'std'.

I use ndk r10c and toolchain 4.8.
I also has enabled c++11 support by adding -std=c++11.

Or, is this feature not supported by Android ndk?

Alvin Schurman

unread,
Dec 2, 2014, 9:37:16 AM12/2/14
to andro...@googlegroups.com
I don't think you need the std:: prefix for stol or its related functions.  You could try to use "stoi" instead of "std::stoi".  If the compiler barks at you then I suggest putting "using namespace std" below your #includes and trying plain "stoi" again.    

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-ndk.
For more options, visit https://groups.google.com/d/optout.

Michael

unread,
Dec 3, 2014, 3:44:17 AM12/3/14
to andro...@googlegroups.com
These functions should be solely in the std::namespace and available since C++11, according to cppreference. There seem to be some C++11 functions that are simply not available in the NDK at least when using libstdc++. See also here: https://code.google.com/p/android/issues/detail?id=53460. Pity that Google has not fixed this issue yet -- it's been known for a while now.

By the way, 'using namespace std;' is almost always a bad idea. It's a big no-no in global scope in header files, and even in translation units I would not allow its usage (with locally-scoped ADL related exceptions, e.g. for swap()).

Dmitry Moskalchuk

unread,
Dec 30, 2014, 8:36:53 PM12/30/14
to andro...@googlegroups.com
Hi,

Probably it's bit outdated, but I'll reply here anyway.

Yes, std::stol is not available in GNU libstdc++ implementation shipped with Android NDK. It's not the only missing functionality - in fact, standard C++11 classes such as std::thread and std::mutex are not available too.

Fortunately, full C++ Standard Library implementation is available out-of-the-box in just released CrystaX NDK 10: https://www.crystax.net/android/ndk/10

You can use it as a drop-in replacement of Google's NDK. Hope that will help.

-- 
Dmitry Moskalchuk
signature.asc

Daniel Tavares

unread,
Jul 8, 2015, 7:12:53 PM7/8/15
to andro...@googlegroups.com
I solved this problem by switching the STL runtime to LLVM libC++.

APP_STL := c++_static

Raj kumar

unread,
Dec 23, 2016, 11:03:51 PM12/23/16
to android-ndk
HI, 
I changed to APP_STL := c++_static in Application.mk. 
So, I am getting following error:

* What went wrong:

Execution failed for task ':app:ndkBuild'.

ndk-build'' finished with non-zero exit value 2


my Application.mk file is as follows

# Android makefile for textsort shared lib, jni wrapper around libtextsort C API


APP_ABI := all

APP_OPTIM := release

APP_PLATFORM := android-21

# GCC 4.9 Toolchain - requires NDK r10

NDK_TOOLCHAIN_VERSION = 4.9

# GNU libc++ is the only Android STL which supports C++11 features

APP_STL := c++_static

APP_BUILD_SCRIPT := jni/Android.mk

APP_MODULES := libbagbash_jni


Please help me to fix this issue.

Thank you in advance.

javacom

unread,
Dec 24, 2016, 10:48:07 AM12/24/16
to andro...@googlegroups.com
Can you show the line of code that's causing this error? 

'stol' is not a member of 'std'.

Regards

Dan Albert

unread,
Dec 28, 2016, 2:37:10 PM12/28/16
to android-ndk
Can you show the line of code that's causing this error? 

'stol' is not a member of 'std'.
Any code using std::sto* and using gnustl will have this problem: https://github.com/android-ndk/ndk/issues/82 

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+unsubscribe@googlegroups.com.

To post to this group, send email to andro...@googlegroups.com.

Raj kumar

unread,
Dec 28, 2016, 3:10:42 PM12/28/16
to andro...@googlegroups.com
HI,
Sorry for late reply,
I could able to fix the issue. It was c++11 configuration issue.

Thank you very much for your support.

On Thu, Dec 29, 2016 at 4:36 AM, 'Dan Albert' via android-ndk <andro...@googlegroups.com> wrote:
Can you show the line of code that's causing this error? 

'stol' is not a member of 'std'.
Any code using std::sto* and using gnustl will have this problem: https://github.com/android-ndk/ndk/issues/82 

On Sat, Dec 24, 2016 at 12:02 AM, javacom <java...@gmail.com> wrote:
Can you show the line of code that's causing this error? 

'stol' is not a member of 'std'.

Regards

idea <edise...@gmail.com> 於 2014年12月2日 上午8:37 寫道:

'stol' is not a member of 'std'.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+unsubscribe@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/48DC6FD9-97CC-4102-9F8A-FBAF5467DD20%40gmail.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "android-ndk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/android-ndk/pQ2Qv8GPcwA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to android-ndk+unsubscribe@googlegroups.com.

To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.

For more options, visit https://groups.google.com/d/optout.



--
Regards,
---------------
Rajkumar
Reply all
Reply to author
Forward
0 new messages