获取指定目录下所有文件名
#include <iostream>
#include <io.h>
#include <string>
#include <vector>
using namespace std;
void getFiles(string, vector<string>&);
int main(int argc, char **argv)
{
vector<string> files;
getFiles("./data", files);
for (int j = 0; j< files.size(); ++j)
{
cout << files[j] << endl;
}
system("pause");
return 0;
}
void getFiles(string path, vector<string>& files)
{
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)
getFiles(p.assign(path).append("\\").append(fileinfo.name), files);
}
else
{
files.push_back(p.assign("").append(fileinfo.name));
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}