解决c++ fstream不支持中文路径
C++解决中文目录的问题
·
- 有两种方式,第一种是使用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
更多推荐
所有评论(0)