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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:43:57+00:00 2026-05-26T05:43:57+00:00

This is actually the program my instructor had provided with us to work with,

  • 0

This is actually the program my instructor had provided with us to work with, i had to make several changes thus far to get it to at least compile:

 #include <dirent.h>
#include <errno.h>
#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <cctype>
#include <cstdio>
#include <string>
#include <list>

using namespace std;
std::string makeString();
std::string path= "/";
DIR*dirp;
struct dirent*direntp;
std::list<string> child_directories;



void dir_traverse(&path, ios::out){
    list<string> child_directories;
    DIR*dirp = opendir(path.data());
    struct dirent*dir_entry = readdir(dirp);
        while(dir_entry !=null){ 
             unsigned char d_type = dir_entry->d_type==DT_OIR?'D' : 'R';
             if(d_type == 'D'){ 
                if(dir_entry->d_name[0]!= '.')
                    {
                    child_directories push_back(dir_entry_d_name);
                }

             }
            out<<'\t'<<d_type<<":"<<dir_entry->d_name<<endl;
            dir_entry= readdir(dirp);
        }
        list<string>::iterator it = child_directories.begin();
        while(it! = child_directories.end())
            {
                dir_traverse(&path + "/" + *it, out);
                it++;
            }
        closedir(dirp);
}

I get the error I have as the title in reference to the dir_traverse function. I am pretty much interested in figuring out what is causing the problem and why. Half of what is going on in the function I don’t really get at the moment, which is probably why I am having this compiling issue. just not up to speed on c/c++ yet 🙂

thanks

edit:

void dir_traverse(string& path, ostream& out){
    list<string> child_directories;
    DIR*dirp = opendir(path.data());
    struct dirent*dir_entry = readdir(dirp);
        while(dir_entry !=NULL){ 
             unsigned char d_type = dir_entry->d_type==DT_DIR?'D' : 'R';
             if(d_type == 'D'){ 
                if(dir_entry->d_name[0]!= '.')
                    {
                    child_directories.push_back(dir_entry_d_name);
                }

             }
            out<<'\t'<<d_type<<":"<<dir_entry->d_name<<endl;
            dir_entry= readdir(dirp);
        }
        list<string>::iterator it = child_directories.begin();
        while(it != child_directories.end())
            {
                dir_traverse(&path + "/" + *it, out);
                it++;
            }
        closedir(dirp);
}
  • 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-26T05:43:58+00:00Added an answer on May 26, 2026 at 5:43 am

    Okay, so you need to make a few changes to your instructor’s sample to get it to compile.

    I’m going to assume you’ve included the four headers needed to compile. I recommend you pull in just the following four symbols from the std namespace, rather than the whole lot. Personally I prefer to refer to std::string in my code.

    using std::string;
    using std::ostream;
    using std::list;
    using std::endl;
    

    Anyway, only the following three lines need to be fixed:

    void dir_traverse(string& path, ostream& out) 
    

    Should be…

    void dir_traverse(const string& path, ostream& out)
    

    Because you later pass in a temporary when you call the function recursively.

                child_directories.push_back(dir_entry_d_name); 
    

    Should be…

                child_directories.push_back(dir_entry->d_name);
    

    This looks like a typo!

        dir_traverse(&path + "/" + *it, out);
    

    Should be…

        dir_traverse(path + "/" + *it, out);
    

    This looks like a typo, too. This is where you create the temporary path string that I mentioned earlier. This must be passed as a const reference (since it is not passed by value).

    As you practise more, you’ll become more attuned to your compiler’s error messages!

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm actually writing an MPI program. This is a basic client / server pattern.
This is actually a non-critical question, but I get this warning most of the
This is actually related to another question I had that was already answered. That
i have this C++ program (actually it's just a snippet) : #include <iostream> #include
Everything seemed so plain and simple until I had to actually program it. What
Actually this is what i want to do; When a condition appears, my program
I was provided this simple C++ [I think] program to investigate the maximum size
This is actually my homework and the question states: The program should determine how
Simple question - what does this actually do? var oq = (ObjectQuery<TEntity>)L2EQuery; return ExecuteFirstorDefault<TEntity>(oq,
I have seen code like this (actually seeing another person type it up): catch

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.