我正在使用以下界面设置硬盘驱动器上文件的路径:
void setPath(const char* path);
此路径将用于基本文件 I/O。
例如,如果我提供一个包含中文字符的路径(例如通过 QString::toUtf8()),这对于 Unix 来说很好,但对于 Windows 来说当然不行,因为内部使用了 wchar/wstring API。
我现在正在寻找一种优雅的方法来使这个接口 UTF-8 在基于 Windows 和 Unix 的系统上兼容。有没有办法避免在基于 Windows 的系统上使用广泛的 API 并继续使用 std::string 和 std::ofstream() ?
在查看 boost::locale 之后,这在我看来是一种处理 UTF-8 编码的可能性。这会是一种方法吗(例如,用 boost::ofstream() 对应物替换 std::ofstream ?)
const std::locale loc = generator.generate(std::locale(), "zh_CN.UTF-8");
std::locale::global(loc);
std::cout.imbue(std::locale());
boost::filesystem::path::imbue(std::locale())
感谢所有帮助。