Problem to convert int to string

Hello,

I use in my code :

int fichier = 1 ;
std::string nomDuFichier = std::to_string(fichier);

And i have compilation error when i compile for android : "error ‘to_string’ is not a member of std."

Do you know why ?

In advance thanks,

Maybe this could help:
to_string() not working for Android

I’m usually using sprintf(), but that might not be the most convenient way…

2 Likes

In your Application.mk put APP_STL := c++_static

1 Like

Ok thanks, this solution make the application crash “in your Application.mk put APP_STL := c++_static”, so i do that :

cocos2d::__String * nomDuFichier = String::createWithFormat("%d.png", fichier);

signe->setTexture(nomDuFichier->_string);

Thanks for your answer,

2 Likes

I’m sorry I forgot to mention you have to remove gnustl and replace it with c++_static.

Anyway you found another way so it’s cool :+1:

1 Like

Ok, no problem, thanks again for your answer :smile:

1 Like

you can also do something like this -

std::stringstream ss;
ss << "I have " << 1000 << " dollars with me";

CCLOG(ss.str().c_str());

This will print a string.
"I have 1000 dollars with me"
you can also use the numbers only to convert to string.

Hope this helps.

Happy Coding :smile:

5 Likes

Ok, very nice, thanks :slight_smile:

Hey, do you know why isn’t this the default configuration? I’ve tried it and it seems to work on my devices at least.

I believe it is the default configuration now.

Hello, I use:
“StringUtils::format(”%d", myInt);"