How can I check if a file exists in my directory before continuing with my program? I have read answers that try opening the file using various methods but my issue is that most of the time, the file I am checking for will be corrupt and cant be opened. This happens in the error checking part of my program and will only be triggered when an error in the preceding code has occurred. I want to check if the file exists, if so then ask to delete it, otherwise just print out some message.
How can I go about this?
(Just deleting and accepting the errors would work, but I'm doing this to learn, so I want to do it properly...)
Edit:
I have downloaded Boost to use the filesystem library and have compiled it, seemingly with no errors, but when I try to compile my program, I get this response:
g++ program.cpp -I <path to>/boost_1_54_0 -o output
Undefined symbols for architecture x86_64:
"boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)", referenced from:
boost::filesystem::exists(boost::filesystem::path const&)in cc1XX8rD.o
"boost::system::system_category()", referenced from:
__static_initialization_and_destruction_0(int, int)in cc1XX8rD.o
"boost::system::generic_category()", referenced from:
__static_initialization_and_destruction_0(int, int)in cc1XX8rD.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
The only places I use boost in the program are:
boost::filesystem::path my_file(s4);
if (boost::filesystem::exists(my_file)){ ...