c++ - 我没有得到目录中文件的实际数量。哪里有问题?

标签 c++ file visual-c++

#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/

相关文章:

c++ - 有人可以解释这个 C/C++ 语法吗?

ios - 通过应用程序中的链接使 pdf 文件可访问

javascript - 使用 require.js 在多个 JS 文件中拆分应用程序的 javascript

c++ - 如何解释 C++ 语法中的 decl-specifier

c++ - 可以在 C++ 中使用 dynamic_cast 进行向上转换和向下转换

c++ - 如何解密被 CryptProtectData 函数加密的数据?

c++ - 分离的线程在退出时崩溃

c++ - 从文件opencv中读取视频

c - 从文本文件中读取数据值以及 C 中的行数和列数

c++ - 了解 C++ 标准的 move 语义