Assume we have code like this:
boost::iostreams::mapped_file_source dev(paFileName.u8string().c_str());
where paFileName is a std::filesystem::path object.
On Windows, the internal character in std::filesystem::path is wchar_t, but boost::iostreams::mapped_file_source seems to only accept variant width character string. Therefore, we convert the fixed width wchar_t string to a variant width char string with method u8string.
The problem is that the conversion apparently causes the ctor of boost::iostreams::mapped_file_source unable to find the file in the filesystem, and the ctor will throw a boost::wrapexcept<std::ios_base::failure[abi:cxx11]> that says "failed opening file: The system cannot find the file specified."
How to fix this problem? Any suggestions? Thanks.
According to the message of the compile-time error:
Somehow Boost.Iostreams tried to convert the
std::filesystem::pathinto aboost::iostreams::details::pathbut failed, because the conversion ctor that accepts the wide character string is not accessible. This problem doesn't happen on Linux, because the filesystem on Linux usually uses UTF-8charstrings as filenames. In contrast, on Windows the filenames are usually UTF-16wchar_tstrings.My workaround is to avoid the conversion ctor mentioned above to be called. I gave a
boost::filesystem::wpathinstead of the originalstd::filesystem::pathto Boost.Iostreams, hoping that the Boost versionwpathis more acceptable to Boost.Iostreams.And it works.