首页 > 解决方案 > WideCharToMultiByte 不在英语操作系统上转换日语

问题描述

我需要将文件名System.Stringstd::string. 我同时使用日文和英文文件名。

对于英文文件名,没有问题。

只有日文文件名不会转换为std::string英文 Windows 10。

我使用WideCharToMultiByte()和代码页 932。

std::string marshal_as(System::String^ str)
{
    std::string convertedstring;
    size_t _size = 0;
    cli::pin_ptr<const wchar_t> _pinned_ptr = PtrToStringChars(str);
    _size = WideCharToMultiByte(932, 0, _pinned_ptr, str->Length, 0, 0, 0, 0);
    if (_size > 0)
    {
        convertedstring.resize(_size);
        char* buffer = &convertedstring[0];
        WideCharToMultiByte(932, 0, _pinned_ptr, -1, &buffer[0], _size, 0, 0);

    }

    return convertedstring;
}

这里str"C:\\files\\ブ種別.pdf"

convertedstring"C:\\files\\ƒuŽí•Ê.pdf"

谁能帮我解决这个问题?

标签: c++stdstringunicode-stringwidechar

解决方案


我的问题已解决。我在控制面板的区域设置中启用了 Beta: Use Unicode UTF-8 for global language support 选项。


推荐阅读