I have next function that reads file:
std::wstring ReadUtf8File( const fs::path& filePath )
{
std::locale curLocale{ std::locale(), new std::codecvt_utf8<wchar_t, 0xefbbbf, std::consume_header> };
std::wifstream wif{ filePath, std::ios_base::binary | std::ios_base::in };
wif.imbue( curLocale );
std::wstringstream wss;
wss << wif.rdbuf();
return wss.str();
}
This function is not only reading file using utf8 encoding according to the BOM, but it also ignores the BOM offset at the beginning of the file.
The problem is that I could not figure out how to write it using templated new std::codecvt<...> to avoid deprecation.
Looking at the header there is no option like codecvt_mode which I definetely need. Please help solving this problem, thanks in advance.