how can I read all file names in a directory that start with a specific word using c++?
nazanin
2016-05-20 20:19:17 UTC
for instance I want to read all the text file names in a directory that start with 'word' like 'word1.txt'....'word200.txt', and there might be all these other files there which I don't want to see their names. what would the C++ code for that be?
Three answers:
Julien
2016-05-20 20:26:22 UTC
That's not in the C++ norm, it depends on system calls. On POSIX-compatible systems you should use readdir (and then strncmp or whatever). On Windows I have no idea.
Here is a copy of the man page: http://pubs.opengroup.org/onlinepubs/009695399/functions/readdir_r.html
anonymous
2016-05-20 23:53:55 UTC
The filesystem library is now the C++ norm (official release C++17). You will have to get a latest compiler and turn on C++17 options (eg gcc).