Convert std::string to String

How do I convert std::string to String?
I know that in a perfect world I use std::string for everything but in this case I actually need to convert std::string to String.

With standard cpp I have seen people use <msclr\marshal.h> but until now I haven’t found the platformIO equivalent. Is there any other way Im forgetting about?

Im pretty new to PlattformIO so any kind of help would be much appreciated :slight_smile:

You can get the std::string’s C-string (const char* via calling c_str() on the object, then feed that in the constructor of String. This will cause double memory usage, String will copy it into a newly allocated buffer. (Henc why equalization is kinda important).

std:string cpp_str = "Hello";
String ard_str = String(cpp_str.c_str());
1 Like