Opening Files with specific file extensions

Hi all,

I was wondering if there is a library or a function that could do the following.

I want to read a file in from the command line argument but only open it if it has the .conf file extension. Of course, it will check for incorrect spelling of the file name itself or if the file is empty.

However, I would like my program to display an error message and terminate if a file without that extension is entered in from the user.

Thanks in advance.
1
2
3
4
5
6
7
8
bool is_conf(const std::string &path){
    auto dot = path.rfind('.');
    if (dot == path.npos || dot + 1 >= path.size())
        return false;
    auto ext = path.substr(dot + 1);
    std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
    return ext == "conf";
}
auto is not a keyword in my compiler for g++/gcc.

I am Ubuntu 14 and compiling through the terminal.
I found my solution. Thanks for the help! I used a substr function to match the .conf with the file input name.
Topic archived. No new replies allowed.