string c++ modules

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Catprog
:warning: Old Version Published before Godot 3 was released.

I am trying to integrate some c++ code into the engine.

I get

error C2440: 'initializing': cannot convert from 'std::string' to 'Variant'

Obviously the parameters and return type for my class are std::string. How do I change them so that I can use Variant?

:bust_in_silhouette: Reply From: Zylann

Godot doesn’t uses STL, and has no clue about what std::string is. You should use the String class provided by Godot. If you can’t, try converting your_std_string.c_str() in a String instead.
It also has to be converted because Godot uses wchar_t characters, which are 2-bytes long. std::string has 1-byte characters. If you still want to use the STL, std::wstring might be easier to work with.

Is their an example of how to use the string type?

Catprog | 2016-06-26 12:17

Well, everywhere in the engine :slight_smile:
It’s a pretty straightforward class, it has concatenation, copy, find, substring etc.
It should be available if you already included variant.h in your C++ file.
You can have a look at the header: https://github.com/godotengine/godot/blob/master/core/ustring.h

Zylann | 2016-06-26 12:28

So to use it in the module I just need to
1)replace std::string with String
2) remove the #include

  1. Then use the ascii method to get a vector of chars to work with. (I think the class I am including only handles ascii)

4)Create a new String with the resulting data.

(It appears that their is already a function for the other code sha256_text().

Thank you for your help. I will try it out when I get time,

Catprog | 2016-06-26 12:42