问题遇到的现象和发生背景
下面这段代码在vscode上可以运行,但是在vs上运行不顺利,只是打印出第一个文件便结束了。
问题相关代码,请勿粘贴截图
#include <stdio.h>
#include <io.h>
#include <string>
int main()
{
//目标文件夹路径
std::string inPath = "C:\\ticket_booking_INF\\Worker\\*";//遍历文件夹下的所有文件
//用于查找的句柄
long handle;
struct _finddata_t fileinfo;
//第一次查找
handle = _findfirst(inPath.c_str(), &fileinfo);
if (handle == -1)
return -1;
do
{
//找到的文件的文件名
printf("%s\n", fileinfo.name);
} while (!_findnext(handle, &fileinfo));
_findclose(handle);
system("pause");
return 0;
}
运行结果及报错内容
不知道是什么情况
我的解答思路和尝试过的方法
网上搜了很多的相似代码都是这个结果
我想要达到的结果
我希望在vs上可以实现文件夹内容的遍历,打印出所有文件名称