欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

解决Win10下_findnext()异常

发布时间:2025/7/14 编程问答 31 豆豆
生活随笔 收集整理的这篇文章主要介绍了 解决Win10下_findnext()异常 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

在win10中,使用文件遍历函数_findnext会报0xC0000005错误
原因:
_findnext()第一个参数”路径句柄”,返回的类型为intptr_t(long long),如果定义为long,在win7中是没有问题,但是在win10中就要改为long long或者intptr_t

下面是示例代码:
---------------------
原文:https://blog.csdn.net/hemmingway/article/details/73716980?utm_source=copy

/* Get all files in a folder specified by path and store the file names in a vector */ void getAllFiles(string path, vector<string> &files) {long long hFile = 0;//long hfile=0;struct _finddata_t fileinfo;string p;if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1) {do {if ((fileinfo.attrib & _A_SUBDIR)) {if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0){files.push_back(p.assign(path).append("\\").append(fileinfo.name));getAllFiles(p.assign(path).append("\\").append(fileinfo.name), files);}}else {files.push_back(p.assign(path).append("\\").append(fileinfo.name));}} while (_findnext(hFile, &fileinfo) == 0);_findclose(hFile);}}

  

转载于:https://www.cnblogs.com/PieDaoChuan/p/9802461.html

总结

以上是生活随笔为你收集整理的解决Win10下_findnext()异常的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。