#include<iostream>
#include<io.h>
using namespace std;
void main()
{
char *filename = "D:\\MyBin\\pic\\*.jpg";
struct _finddata_t fileinfo;
long handle;
handle = _findfirst(filename,&fileinfo);
if(handle == -1) cout<<"fail..."<<endl;
else
cout<<fileinfo.name<<endl;
while(!_findnext(handle,&fileinfo))
{
cout<<fileinfo.name<<endl;
}
_findclose(handle);
system("pause");
}
结果如图
本文展示了一个使用C++进行文件搜索的简单程序实例。该程序利用了_findfirst和_findnext函数来查找指定目录下的所有.jpg文件,并打印出文件名。通过这个例子,读者可以了解到如何在C++中实现基本的文件搜索功能。
481

被折叠的 条评论
为什么被折叠?



