1. 有两种方式,第一种是使用C++17 u8path
#define __cplusplus 201703L
#include <fstream>
#include <filesystem>

int main()
{
    std::fstream fs(std::filesystem::u8path(u8"D:\\中文.txt"),ios::in);
    if(fs.is_open())
    {
        cout<<"open success"<<endl;
    }
    else
    {
        cout<<"open failed"<<endl;
    }
    getchar();
    return 0;
}

 运行结果:

open success

2. 第二种方式是使用boost库

#include <boost/nowide/fstream.hpp>
int main()
{
    //boost
    boost::nowide::fstream fs("D:\\中文.txt");
    if(fs.is_open())
    {
        cout<<"open success"<<endl;
    }
    else
    {
        cout<<"open failed"<<endl;
    }
}

运行结果:

open success

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐