Re: String conversion

Jonathan Wakely via Gcc-help <[email protected]>
Newsgroups gmane.comp.gcc.help
Message-ID <CAH6eHdQXSXvBCqEt0zdvHPBkYwa+warcdM1x6L9ETVV-4sYYgg@mail.gmail.com>
On Fri, 28 Nov 2025 at 19:48, jh--- via Gcc-help <[email protected]> wrote:
>
> Hi,
>
> This is maybe not the absolute best place to ask this question, but as
> experts of the C++ specification, some reader might be able to answer my
> question.
> There are some places where I need to convert a wstring to utf-8 (both
> ways). There was the seemingly convenient, but now deprecated (because
> of some advanced problems) wstring_convert mechanism. Is there a
> replacement native way to do this conversion?


No, it was deprecated without a replacement. You can still use
wstring_convert with GCC though.

There's ongoing work to add a better feature to a future version of
C++, via the https://wg21.link/p2728 proposal. There's an internal
implementation of that in GCC 14 and later, but there are no
guarantees about its availability or its API being stable, because
it's currently only intended for internal use. But that only converts
between Unicode encodings, and I don't know what you mean by
"wstring", as that's just a type not an encoding. If your wstring
contains UTF-32 data you can use std::__unicode::_Utf8_view to convert
it to UTF-8, and use std::__unicode::_Utf32_view to convert to UTF-32.

You can use POSIX iconv to convert between any encodings. And of
course there's https://icu.unicode.org/ which is the gold standard.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.