# **[](https://en.cppreference.com/w/cpp/header/codecvt)** provides locale-based character encoding conversion facets, primarily for converting between UTF-8, UTF-16, and UTF-32. It's part of the locales system, which is complex and largely superseded by explicit UTF-8 handling in modern C++. Most new code avoids this in favor of dedicated UTF-8 libraries or C++20 ``. It's mainly present for compatibility with legacy code. ## Example This example uses a codecvt facet to convert a UTF-8 string to a wide character string via a `wstring_convert` wrapper. ```cpp // compile: g++ -std=c++11 -o codecvtexample codecvtexample.cpp // run: ./codecvtexample // description: UTF-8 to UTF-32 conversion via codecvt #include #include #include #include int main() { std::wstring_convert> converter; std::string utf8_str = "hello"; std::wstring wide = converter.from_bytes(utf8_str); std::cout << "converted: " << wide.size() << " wide chars\n"; return 0; } ```