转 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);

 

 

你可能感兴趣的:(转 ifstream 读取中文路径)