Using Fstream to open every text file in a folder?

Hi, How would I use fstream to open every text file in a folder? I am basically opening a text file (that i currently define the name of) running a loop of getline and storing the lines i need in a string array. Open next , repeat until all are done.

I would like to be able to point to a directory and then it opens the first file (does the loop) closes , opens next etc until it reaches the end. How would it find the first file does it search them by name or does it search by date? I assume these are all parameters you can set I am just not sure how!

Thanks?
Last edited on
Standard C++ does not provide a way for navigating OS filesystems, but Boost's Filesystem library can do what you want.

http://www.boost.org/doc/libs/1_54_0/libs/filesystem/doc/index.htm
Thank you, I have no experience with boost would you be able to give any example of how to do what im looking for within the boost system or at least point me in the right direction :P ? cheers!
Here is a link to the tutorial from the page Zhuge gave you:
http://www.boost.org/doc/libs/1_54_0/libs/filesystem/doc/tutorial.html
Yea I have looked over it and checked it out before but im only a few weeks into programming part time , and I really cant make much sense of it. Is the boost file system the only solution for opening all text files in a folder when you dont know the names of the files ?
closed account (Dy7SLyTq)
no win32 has something in the api and *nix has dirent.h

edit: but unless im writing an os specific app i would personally use boost, because the code to (un)include the files and code neccesary wouldnt make sense
Last edited on
Yea unfortunately I have no experience with API either, any examples or suggestions would be great with either API or using boost!
closed account (Dy7SLyTq)
well boost and win32 are apis, but dirent isnt. just google listing directories in c++ on {insert platform of choice}. it will give you links to techniques and code used
Topic archived. No new replies allowed.