C++:判断输入文件路径的该文件类型是否为jpg、png、mp4、mp3

C++:
1、判断输入文件路径的该文件是否存在;
2、然后判断类型是否为jpg、png、mp4、mp3;
3、如果是则结束,不是则需要继续重新输入。
对于1和3步骤我不知道用哪个具体判断函数;
对于2,我的方法是截取出从路径最后开始截取到首个''.''这个位置的内容,然后用if语句判断该内容。各位大佬们有没有更好的方法,求分享!

// 需要编译器支持C++17

#include <filesystem>
#include <iostream>

int main()
{
    while (1)
    {
        std::cout << "Please input file path: ";
        std::filesystem::path path;
        std::cin >> path;
        if (!std::cin)
            break;
        if (!std::filesystem::exists(path))
        {
            std::cerr << "File " << path << " does not exist.\n";
            continue;
        }
        auto ext = path.extension();
        if (ext == ".jpg" || ext == ".png" || ext == ".mp4" || ext == ".mp3")
            break;
        else
            std::cerr << "The file type is " << ext << ", which is not \".jpg\", \".png\", \".mp4\", or \".mp3\".\n";
    }
    return 0;
}

获取文件流前两位byte
255216 jpg
13780 png