Yes. Try to open the file, and check the errors. Windows gui code has tools to search for a file built in. Unix has tools to do this as well, but I don't know if its better to link in a library or to just ask the OS on unix.
The extension ... is part of the file name you used... if you do not know it, and used a wildcard search, the results of the search will give the name and therefore its extension.
If a file couldn't be opened because it didn't exist or whatever...
1 2 3 4 5 6 7 8
#include <iostream>
#include <fstream>
int main()
{
if (std::fstream{FILE_NAME}) std::cout << "file exists\n";
else std::cerr << "file couldn\'t be opened (not existing or failed to open)\n";
}
@JLBorges Too bad not everyone has access to this library (filesystem). It would simplify file handling a lot. Boost has it, but you need to link a shared library.