Convert Juce::String to std::string and vice versa


#1

I haven’t found a clean way to do either, yet. Any clues?


#2

maybe doing

juce::String js = “something to try”;
std::string ss = (const char*) js;

and the opposite

std::string ss = “another try”;
juce::String js = (const char*) ss.c_str();

probably ?


#3

and std::string operator in the juce::String would not be hard to add… at all…


#4

I know it’s ten years later but I can’t resist updating this thread to help newcomers like myself in the future.

This may not have been supported ten years ago but it looks to be in now!

String::String (const std::string & )
Creates a string from a UTF-8 encoded std::string.

std::string String::toStdString () const
goes back the other way.


#5