【发布时间】:2019-05-06 15:28:59
【问题描述】:
我需要检查文件夹中的文件名是否以 .config 结尾。所以我使用下面的代码。
#include "stdafx.h"
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <fstream>
#include <iostream>
using namespace std;
void main(){
DIR *dirp;
struct dirent *dp;
char prnStr[254];
if ((dirp = opendir("D:/New folder/")) == NULL) {
cout << "Could not open directory!!";
return;
}
if ((dp = readdir(dirp)) != NULL) {
prnStr << dp->d_name;
size_t findprn = prnStr.str().find(".config");
if ((int)findprn != -1) {
cout << "Found .config File!!!!!";
}
else {
cout << "No .config files detected at this time...";
}
}
}
在这一行出现错误 prnStr d_name; as 错误:表达式必须具有整数或无范围枚举类型
【问题讨论】:
-
prnStr << dp->d_name毫无意义。目前尚不清楚您认为它应该实现什么,但无论它是什么,它都不会那样做。prnStr.str()也是如此
标签: c++ visual-c++ directory dirent.h