system
1
|
|
|
|
Attention |
Topic was automatically imported from the old Question2Answer platform. |
|
Asked By |
markwiering |
Hello there!
With Godot, when using C++ modules, how do I convert Godot’s String to C++'s std::string ?
I found this page here ( https://forum.godotengine.org/110221/c-string-to-string ) explaining how to convert std::string to Godot’s String, but not a page that explains how to do the opposite.
So… if anybody knows… how do I convert Godot’s String to std::string ?
|
|
|
|
Reply From: |
Zion |
For Godot 3.3, could likely use unicode_str()
. Reference:
const wchar_t *String::unicode_str() const {
return godot::api->godot_string_wide_str(&_godot_string);
}
For Godot 4.0, I made the conversion using utf().get_data()
in the following sample:
String foo = "helloworld"; // Godot's String
std::string stdstring_foo(foo.utf8().get_data());
std::cout << "stdstring_foo: " << stdstring_foo << std::endl;
// outputs:
// stdstring_foo: helloworld
Reference:
Or could like use ascii().get_data()
too: