Copying a string with no encodage into a c-string is quite easy:
auto to_c_str(std::string const& str) -> char* {
auto dest = new char[str.size() + 1];
return strcpy(dest, str.c_str());
}
But how can I do that with a std::u8string
? Is there a STL algorithm that can help with that?
I tried this:
auto to_c_str(std::u8string const& str) -> char8_t* {
auto dest = new char8_t[str.size() + 1];
return std::strcpy(dest, str.c_str());
}
But of course, std::strcpy
is not overloaded for utf8 strings.