wofstream 输出CString Unicode|路径中文名支持

来源:互联网 发布:淘宝互刷平台2016 编辑:程序博客网 时间:2024/05/17 07:14

 

wofstream hFile(L"D://Res.xml",ios::app); // _SH_DENYRW is deny read and write

   

if (!hFile) // if the file could open, hFile is a handle, else is zero

{

cout << "write fail!" << endl;

cout << "access is denies,maybe the file is readonlys,or use deny read opened of other process." << endl;

}

else

{

hFile.imbue(std::locale("chs"));

hFile << NewXml.GetString() << std::endl;

cout << "write success!" << endl;

}

hFile.close(); // opened file need close.

}

catch(...)

{

wofstream hFile(L"D://RPT.txt",ios::app);

hFile.imbue(std::locale("chs"));

hFile << strFileName.GetString() << std::endl;

cout << "文件转化出错!" << endl;

}

 

 

//================中文路径===============

locale &loc=locale::global(locale(locale(),"",LC_CTYPE));

myXmlFile.Open(strFileName);

if(myXmlFile.GetRoot()->IsNull())

{

wofstream hFile(L"D://RPT.txt",ios::app);

hFile.imbue(std::locale("chs"));

hFile << strFileName.GetString() << std::endl;

cout << "文件转化出错!" << endl;

hFile.close();

return -1;

}

locale::global(loc);

 

原创粉丝点击