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

  • Home
  • SEARCH
  • 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 8998741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:04:36+00:00 2026-06-16T00:04:36+00:00

I have a function inside my program to count the number of the files

  • 0

I have a function inside my program to count the number of the files in a given directory. The function takes the input parameters as the name of the directory and the extension of the filename (type of files which have to counted in the directory).

I want to make it generic so that the caller of the function can specify any number of file extensions which can be taken as the input parameters and then the specific files having those extensions are counted.

void getNames(string dirName,  string fileExtension1, string fileExtension2, string fileExtension3){

vector<string> fileNames = //do some operations

if(fileType == fileExtension1 || fileType==fileExtension2....){
//increase count
}

return fileNames;
}

How do I change this function so that it takes any number of parameters and then the uses the same parameters inside the function to calculate the number of files?

  • 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-16T00:04:36+00:00Added an answer on June 16, 2026 at 12:04 am

    Neatest way is to pass in a vector of extensions

    void getNames(string dirName, const vector<string>& fileExtensions)
    

    Now your if will be inside a for loop

    for(int i = 0; i<fileExtensions.size();i++){
    
        if(fileType == fileExtension[i]){
            //increase count
            break;// this might be needed to ensure no multiple positives? depending on what you want to do.
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that takes a By element, By by = By.xpath(xpathString). Inside
In my program I have function to create log. Inside the function I check
I have this function inside my program: void CBar::NavigateComplete2(IDispatch *pDisp, VARIANT *URL) { try
I have an AJAX function inside a javascript file and I want it to
I have a function defined inside the script tags of head.(in a JSP) I
I have the following function defined inside my linked list class. The declaration in
Inside my Controller i have function that runs after user clicks on item, which
I have a bit of a quandary. I need to call a function inside
I have a function that is often called inside of other functions, and I'd
I have a function void foo() and inside foo I call the function void

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.