#include <windows.h>
#include <iostream>
using namespace std;
int main() {
bool x = true
int i = 0;
wchar_t* file = L"d:/tester/*.txt";
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
hFind = FindFirstFile(file, &FindFileData);
if( hFind == INVALID_HANDLE_VALUE ) {
cout << "find failed\n";
} else {
while(x) {
i++;
x = FindNextFile( hFind ,&FindFileData );
}
}
cout << "\nnumber of files in the directory : " << i << endl <<endl ;
}
我得到的输出是:
查找失败
目录中的文件数:0
我哪里错了?我想在目录中计算 .txt 文件的数量。
最佳答案
您在路径中使用了无效的斜线。在 Windows 中,反斜杠使用“\”而不是“/”。提醒一下,在将反斜杠放入字符串时,应该在前面加上另一个斜杠:“\\”。
关于c++ - 我没有得到目录中文件的实际数量。哪里有问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6568470/