问题:
有时候用ifstream或ofstream打开带有中文路径的文件会失败。

例如:

    ofstream outFile("f:\\新建文件夹\\fuck.xml",ios_base::trunc | ios_base::out | ios_base::binary);
    outFile<<"<xml></xml>";
    outFile.close();

解决方法1:

使用wofstream

    wofstream outFile(_T("f:\\新建文件夹\\fuck.xml"),ios_base::trunc | ios_base::out | ios_base::binary);
    outFile<<_T("<xml></xml>");
    outFile.close();

解决方法2:

1、使用C语言的函数设置为中文运行环境
setlocale(LC_ALL,"Chinese-simplified");

2、使用STL函数设置为系统语言环境
std::locale::global(std::locale("")); 

    std::locale::global(std::locale(""));
    ofstream outFile("f:\\新建文件夹\\fuck.xml",ios_base::trunc | ios_base::out | ios_base::binary);
    outFile<<"<xml></xml>";
    outFile.close();

相关文章:

  • 2022-03-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-11
  • 2022-12-23
  • 2022-01-28
猜你喜欢
  • 2022-12-23
  • 2021-10-21
  • 2022-02-02
  • 2022-12-23
  • 2022-01-31
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案