[C++]fstream与中文路径的问题
2012-12-21 14:05
106 查看
一、开始
用C++的fstream打开中文路径或者中文文件名的文件时,可能会有乱码或者打不开的问题。
这里返回的是0,一般的原因都是路径的问题。
二、方法
//设置为系统缺省,并将原来的locale返回保存在loc中
std::locale loc
= std::locale::global(std::locale(""));
ifstream ifs(strFileName);
if(!ifs.is_open())
{
return0;
}
ifs.close();
//设置回原来的编码,默认情况下程序开始的locale
为"C"
std::locale::global(loc);
return1;
三、参考
http://new.cplusplus.com/reference/std/locale/locale/
http://social.msdn.microsoft.com/Forums/zh-CN/vcgeneral/thread/0fb287af-bb58-4c60-a3da-14fe84c16948
http://www.cppblog.com/deane/archive/2011/08/11/153007.html
用C++的fstream打开中文路径或者中文文件名的文件时,可能会有乱码或者打不开的问题。
ifstream is(strFileName);
if(!is.is_open())
{
return0;
}
这里返回的是0,一般的原因都是路径的问题。
二、方法
//设置为系统缺省,并将原来的locale返回保存在loc中
std::locale loc
= std::locale::global(std::locale(""));
ifstream ifs(strFileName);
if(!ifs.is_open())
{
return0;
}
ifs.close();
//设置回原来的编码,默认情况下程序开始的locale
为"C"
std::locale::global(loc);
return1;
三、参考
http://new.cplusplus.com/reference/std/locale/locale/
http://social.msdn.microsoft.com/Forums/zh-CN/vcgeneral/thread/0fb287af-bb58-4c60-a3da-14fe84c16948
http://www.cppblog.com/deane/archive/2011/08/11/153007.html
相关文章推荐
- fstream如何打开中文路径 - [C/C++]
- vs2005环境,fstream不支持中文路径的问题
- 解决:VS 2005/2008 中 fstream 不能处理带有中文路径的问题
- 解决VS2005中fstream不能打开带有中文路径文件的问题
- fstream 读写中文路径的问题
- 解决fstream.open()不能正确读取中文路径的问题
- VS2005 FSTREAM 不能打开中文路径名文件的问题!
- 用fstream打开含中文路径文件时失败的问题。
- fstream和 中文路径问题
- 关于std::fstream以及std::ifstream打开中文路径名失败的问题和解决方法
- fstream的使用和打开时存在中文中文路径可能失败的问题,其他中文问题都可以尝试采用如下方法
- 很经典的问题---在VC++ 2005中fstream对象无法访问中文路径下的文件,包括英文路径下的中文名文件。
- 解决:VS 2005/2008 中 fstream 不能处理带有中文路径的问题
- 解决:VS 2005/2008 中 fstream 不能处理带有中文路径的问题
- c++中sqlite中文路径创建数据库失败的问题
- 关于std::fstream以及std::ifstream打开中文路径名失败的问题和解决方法
- fstream打开中文路径问题
- 解决fstream不能打开带有中文路径文件的问题
- 解决fstream不能打开带有中文路径文件的问题
- fstream如何打开中文路径 - [C/C++]