Currently using WSL2 Ubuntu, G++20.
What are some recommended ways to convert wchar_t * to char * in C++20? I have seen similar posts created several years ago, but I wasn't sure if they were still viable as a solution or if they were deprecated.
Currently using WSL2 Ubuntu, G++20.
What are some recommended ways to convert wchar_t * to char * in C++20? I have seen similar posts created several years ago, but I wasn't sure if they were still viable as a solution or if they were deprecated.
As far as I know, wcstombs (and wcsrtombs) is still relevant in C++ 20:
#include <iostream>
#include <clocale>
#include <cstdlib>
int main()
{
std::setlocale(LC_ALL, "en_US.utf8");
// UTF-8 narrow multibyte encoding
const wchar_t* wstr = L"z\u00df\u6c34\U0001d10b"; // or L"zß水"
char mbstr[11];
std::wcstombs(mbstr, wstr, 11);
std::cout << "multibyte string: " << mbstr << '\n';
}