Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8018445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:07:56+00:00 2026-06-04T21:07:56+00:00

I wrote a program using boost filesystems almost a year ago, and I am

  • 0

I wrote a program using boost filesystems almost a year ago, and I am now trying to go back and use that for a reference, but I’m not sure exactly what is going on with the code, and if there might be a better way to do it.

Here is what I had done to iterate through a directory.

vector <directory_entry> entry;
copy(directory_iterator("path"), directory_iterator(), back_inserter(entry));

This gets me a vector with directory entries for all of the files and directories inside the directory at “path”

Then I would sort them into two vectors of paths, one for files, one for directories, using is_regular_file.

I was working with openAL, and I would have to do this type of conversion to get things working.

path fp = file[0]; //file a vector of directory_entry
string fps = fp.string();
buffer[0] = AlutCreateBufferFromFile(fps.c_str());

And this worked, but I am thinking this all must not be very correct how I’m using it. Anyways, I just wanted to see if anyone could give me a little advice.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:07:58+00:00Added an answer on June 4, 2026 at 9:07 pm

    Your code looks correct.

    You can avoid a couple variable declarations like so:

    buffer[0] = AlutCreateBufferFromFile(file[0].string().c_str());
    

    You can also avoid copying the directory entries into a vector and iterate over the directory entries directly:

    directory_iterator cur("path");
    directory_iterator end;
    while (cur != end)
    {
        path p = *cur;
        ...  // use p
        ++cur;
    }
    

    In C++11, you can improve on the loop further with lambdas:

    for_each(directory_iterator("path"), directory_iterator(), [](const path& p)
    {
        // use p
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a program using Tweepy that I can run on my home computer
I wrote a program using sqlite but when I run it there seems no
I'm trying to use some code that I wrote on another computer that splits
I wrote a c++ program using boost library in Xcode. Here is my code.
I wrote a little program using fork to create new processes which use pipe
I wrote a program in C++/OpenGL (using Dev-C++ compiler) for my calculus 2 class.
I wrote a program to click on an application automatically at scheduled time using
Here I wrote a C program which executes hi.sh file using system call. Here
I am using windows 7 and program in Netbeans platform. I have wrote this
So I wrote a project-management program for a small business using Microsoft Access 2007.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.