C++如何支持中文路径
‘在写程序的时候,发现当含有中文路径的时候,文档读取便会失败。
我使用的路径转化代码如下,将路径中所有的”“ 转换为"\“。
CString transFile2Path(CString cs)
{
CString re=cs;
int srt_pos = 0;
int find_pos = -1;
while(1)
{
find_pos =re.Find("\",srt_pos);
if(find_pos ==-1)
{
return re;
}
re.Insert(find_pos,"\");
srt_pos=find_pos+2;
}
return re;
}网上有说:
以下示例如何用宽字符API处理中文路径和文件名
#include <io.h>
#include <stdio.h>
void process_directory(const wchar_t * filespec) // 分析目录,遍历所有满足条件的文件
{
struct _wfinddata_t fileinfo;
intptr_t handle;
if ((handle=_wfindfirst(filespec, &fileinfo)) == -1L)
{
perror("Files open error");
}
else
{
do
{
// 处理文件
} while (_wfindnext(handle, &fileinfo) == 0);
_findclose(handle);
}
}
int main()
{
process_directory(L"C:\数据\*.*");
return 0;
}http://bbs.csdn.net/topics/330118362
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇:没有了
