#include <filesystem>
#include <iostream>
#include <clocale>
#include <windows.h>
int main(int argc, char* argv[])
{
SetConsoleOutputCP(CP_UTF8);
std::setlocale(LC_CTYPE, ".65001");
std::cout << std::filesystem::path(L"中文").string() << std::endl;
}
The code above compiled with llvm-mingw results in error at runtime:
libc++abi: terminating due to uncaught exception of type std::__1::__fs::filesystem::filesystem_error: filesystem error: in __wide_to_char: Illegal byte sequence
With clang-cl, it correctly prints the path to Console. Checked MS STL source code, it retrieves UTF-8 code page from ___lc_codepage_func.
https://github.com/microsoft/STL/blob/cbe2ee99caf122555a305d18f69e57c75b3fe5ec/stl/src/filesystem.cpp#L232-L244
The code above compiled with
llvm-mingwresults in error at runtime:With
clang-cl, it correctly prints the path to Console. Checked MS STL source code, it retrieves UTF-8 code page from___lc_codepage_func.https://github.com/microsoft/STL/blob/cbe2ee99caf122555a305d18f69e57c75b3fe5ec/stl/src/filesystem.cpp#L232-L244