jacksondunstan/UnityNativeScripting

can't use std::string?

sonygod opened this issue · 1 comments

can't use std::string?

how to implement Debug.Log("hello world"+2019)?

Hi @sonygod, you're free to use std::string if you like. Debug.Log takes an System.Object in C#, so you'll need to pass a System::Object to Debug::Log in C++. System::String derives from System::Object, so you can pass one of them. The most useful constructor for creating the System::String on the C++ side, as in your example, is probably the one that take a const char* (a.k.a. C string). You can easily get one of those from std::string by calling the c_str member function. Putting this all together, here's how your example could be written in C++:

std::stringstream ss;
ss << "hello world" << 2019;
System::String message(ss.str().c_str());
Debug::Log(message);