梁某人

发展才是硬道理

导航

转 ifstream 读取中文路径

感谢互联网。

 

代码
static std::vector<wchar_t>     s_wchar_buf((size_t)128);
    size_t lengthUnicode 
= MultiByteToWideChar(CP_ACP, 0, strFileName.c_str(), strFileName.size(), NULL, 0);
    
if (s_wchar_buf.size() < lengthUnicode + 1)
    {
        s_wchar_buf.resize(lengthUnicode 
* 2);
    }
    wchar_t
* szUnicode = &s_wchar_buf[0];
    MultiByteToWideChar(CP_ACP, 
0, strFileName.c_str(), strFileName.size(), szUnicode, lengthUnicode);
    szUnicode[lengthUnicode] 
= 0;

    ifstream ifs(szUnicode, ios::
in|ios::ate);

 

 

posted on 2010-09-10 23:59  涛仔28  阅读(882)  评论(0编辑  收藏  举报