简体   繁体   中英

Program not counting file extensions

I'm working on a project for school, it involves going into a specified file path and counting file extensions. However for some reason mine isn't counting them. The way I see it, either the regex I'm using for my file extensions aren't valid, or the directory iterator was done incorrectly. However, I've been playing with it for hours and I'm not getting it regex: regex extensions("\\.(java|class)");

directory iterator:

void nrScan(regex extensions, path const& f, map<string, int> &numExtensions)
{
    for (directory_iterator d(f), e; d != e; d++)
    {
        string extension = d->path().extension().string();
        int count = 0;
        if (regex_search(extension, extensions))
        {
            numExtensions[extension]++;
            count++;
        }
        cout << count << endl;
    }
}

Your regular expression looks like extended regular expression. You must make sure regex_search uses extended RE rather than basic RE to do the search.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM