The problem that the third-party library does not support Chinese Characters in windows

Source: Internet
Author: User

1. In mac environments, since the mac file opening function originally supports utf8 character paths, you can directly input Chinese characters without modifying the third-party library code.
2. Because windows functions do not support utf8 characters, you need to modify the third-party library code.
Modification method:
1. Find all the places where fopen is used in the third-party library. If these files reference the same file, you can add a macro to the file to replace fopen (). The Code is as follows:

. H

#ifdef _WIN32std::wstring Utf8ToUnicode(const char* buf);#define fopen(a, b) _wfopen(Utf8ToUnicode(a).c_str(), Utf8ToUnicode(b).c_str())#endif

. Cpp

#ifdef _WIN32#include <Windows.h>#include <vector>std::wstring Utf8ToUnicode(const char* buf){    int len = ::MultiByteToWideChar(CP_UTF8, 0, buf, -1, NULL, 0);    if (len == 0)     {        return L"";    }    std::vector<wchar_t> unicode(len);    ::MultiByteToWideChar(CP_UTF8, 0, buf, -1, &unicode[0], len);    return &unicode[0];}#endif

Windows character conversion functions can refer to: http://www.cnblogs.com/gakusei/articles/1585211.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.