code :
#include <string.h>
#include <fstream>
#include <iostream>
#include <memory>
#include <sstream>
#include <array>
#include <vector>
#include <map>
#include <dirent.h>
inline bool ends_with(std::string const & value, std::string const & ending);
std::vector<std::string> getFilesInDir(std::string path);
std::map<std::string, int> solve(std::string searchQuery, std::string pth);
inline bool ends_with(std::string const & value, std::string const & ending) {
if (ending.size() > value.size()) return false;
return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
}
std::vector<std::string> getFilesInDir(std::string path) {
DIR *dir;
struct dirent *ent;
const char * constPath = std::string{path}.c_str();
std::vector<std::string> directories{};
if ((dir = opendir(constPath)) != NULL) {
/* print all the files and directories within directory */
while ((ent = readdir (dir)) != NULL) {
auto pos = directories.end();
// if(ends_with(ent->d_name, "log"))
directories.insert(pos, ent->d_name);
}
closedir(dir);
} else {
/* could not open directory */
perror ("");
return directories; //TODO: change this line to throw an exception and return nothing
}
return directories;
}
int main() {
int i = 0;
auto files = getFilesInDir("Users");
for(i = 0; i < files.size(); i++) {
std::string file = files.at(i);
printf("file : %s\n", &file);
}
}
I compile with :
g++ - std=c++0x Analyzer.cpp
compiles just fine with an warning for the printf. when I do :
ls -al a.out
it tells me its an executable -rwxr-xr-x 1 Kevin staff 8720 Feb 21 19:50 a.out
but when I try to do ./a.out
it gives me no such file or directory
I'm not sure what's going on here compilation is throwing no errors just a warning about the printf in the main and the ls -al
is telling me the file is an executable. When I remove the method call for getFilesInDir()
it compiles and runs fine. If anyone has faced this problem and found a solution your help will be gladly appreciated.
Also the operating system for the machine I'm using is MacOS 64 bit architecture.
Aucun commentaire:
Enregistrer un commentaire