I need to check whether file name ends with .config present in a folder. So I'm using below code.
#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...";
}
}
}
Getting error at this line prnStr << dp->d_name; as Error: Expression must have integral or unscoped enum type
It sounds like you want to use a std::ostringstream
. Change prnStr
to be such an object.
Change the line
char prnStr[254];
to
std::ostringstream prnStr;
On a separate note, you are looking for a .config
file. Maybe you should change the line
cout << "Found .prn File!!!!!";
to
cout << "Found .config File!!!!!";
and change
cout << "No .prn files detected at this time...";
to
cout << "No .config files detected at this time...";