0 votes

Does anybody with good knowledge in GDNative (C++) happen to know how to convert an interger to string? I've ran into compiling errors trying to get it to work:

gdtest.cpp:

#include <iostream>
#include <string>
#include <cmath>

using namespace godot;
using namespace std;

String math(){
    int number = 6;
    return godot::String(to_string(number));
}

This is what the error says:

src\gdtest.cpp(11): error C2440: '<function-style-cast>': cannot convert from 'std::string' to 'godot::String'

Any info on how to convert to string would be great! Thanks!

in Engine by (203 points)

1 Answer

0 votes
Best answer

Try sending const char* to godot::String's constructor, instead of std::string:

return godot::String( to_string(number).c_str() );
by (2,288 points)
selected by

It works thanks! Despite some examples of GDScript, it felt completely as if I entered uncharted territory. Hopefully this answer will help others figuring out how to convert to string.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.