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 4618154
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:13:33+00:00 2026-05-22T02:13:33+00:00

the example code on the boost website is not working. http://www.boost.org/doc/libs/1_46_1/libs/filesystem/v3/doc/tutorial.html#Using-path-decomposition int main(int argc,

  • 0

the example code on the boost website is not working. http://www.boost.org/doc/libs/1_46_1/libs/filesystem/v3/doc/tutorial.html#Using-path-decomposition

int main(int argc, char* argv[])
{
  path p (argv[1]);   // p reads clearer than argv[1] in the following code

  try
  {
    if (exists(p))    // does p actually exist?
    {
      if (is_regular_file(p))        // is p a regular file?   
        cout << p << " size is " << file_size(p) << '\n';

      else if (is_directory(p))      // is p a directory?
      {
        cout << p << " is a directory containing:\n";

        typedef vector<path> vec;             // store paths,
        vec v;                                // so we can sort them later

        copy(directory_iterator(p), directory_iterator(), back_inserter(v));

        sort(v.begin(), v.end());             // sort, since directory iteration
                                          // is not ordered on some file systems

        for (vec::const_iterator it (v.begin()); it != v.end(); ++it)
        {
          path fn = it->path().filename();   // extract the filename from the path
          v.push_back(fn);                   // push into vector for later sorting
        }
      }

      else
        cout << p << " exists, but is neither a regular file nor a directory\n";
    }
    else
      cout << p << " does not exist\n";
  }

  catch (const filesystem_error& ex)
  {
    cout << ex.what() << '\n';
  }

  return 0;
} 

two error messages when compiled in visual studio 2010 for the line path fn = it->path().filename();

The first error is: 'function-style cast' : illegal as right side of '->' operator and the second error is: left of '.filename' must have class/struct/union

Also, when I mouse over path() it says: class boost::filesystem3::path Error: typename not allowed

  • 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-05-22T02:13:33+00:00Added an answer on May 22, 2026 at 2:13 am

    This section (for‘s body) is problematic:

      path fn = it->path().filename();   // extract the filename from the path
      v.push_back(fn);                   // push into vector for later sorting
    
    1. it points to path objects, so I don’t see why path() is called. Seems that it should be replaced with it->filename()
    2. you push filenames at the end of the same vector, so after the loop you will have the vector containing the list of files twice, first with pathnames then just filenames.

    EDIT: Looking at the original example I see that these are your modification. If you want to store filenames instead of printing them, define another vector of string or path and store filenames in it, don’t reuse the first one. And removing the call to path() should solve the compilation problem.

    EDIT 2: as a cute BTW, you can achieve both directory traversal and filename extraction in one pass using std::transform instead of std::copy:

    struct fnameExtractor {  // functor
      string operator() (path& p) { return p.filename().string(); }
    };
    
    vector<string> vs;
    vector<path> vp;
    transform(directory_iterator(p), directory_iterator(), back_inserter(vs),
              fnameExtractor());
    

    Same using mem_fun_ref instead of fnameExtractor functor:

    transform(directory_iterator(p), directory_iterator(), back_inserter(vp),
              mem_fun_ref(&path::filename));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble implmenting the 3rd parameter in the function documented here: http://www.boost.org/doc/libs/1_39_0/doc/html/boost_asio/reference/async_read_until/overload4.html What
I have this example code: #include template<class T> class Class { public: typedef boost::shared_ptr<Class<T>
There is the following example code in the BOOST MPL documentation of the find
Is there good example code or a test project for explaining the Model–view–presenter (MVP)
Many C++ books contain example code like this... std::cout << Test line << std::endl;
here is my example code: Public Class Parent Private _TestProperty As String Private WithEvents
There is this example code, but then it starts talking about millisecond / nanosecond
Does anyone have an example (code or a link) that will allow me to
I have the following example code: class A(object): def __init__(self, id): self.myid = id
I see a lot of example code for C# classes that does this: public

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.