R
Rob Mandeville
I need to open a file, and determine if:
1: I actually opened it
2: I couldn't open it because it doesn't exist, or
3: I couldn't open it for other reasons, such as file permissions.
I'm using ifstream for this, and I can tell if it opened or not. But if
it doesn't open, how do I tell whether the file exists or not?
Here's what I have so far:
code:
ifstream foo();
foo.open(filename);
if(foo.is_open()){
// It's open...read it.
}else if(BAR){ // file does not exist
// handle file does not exist case
}else{
// complain to user that you can't open the file
}
So I need to know what I can put in place of BAR.
Can I trust the value of errno in this case? Is BAR "(errno==ENOENT)"?
I need the same code working in VC++ and unix/g++, so I'm looking for a
platform-agnostic solution, if one exists.
--Rob
1: I actually opened it
2: I couldn't open it because it doesn't exist, or
3: I couldn't open it for other reasons, such as file permissions.
I'm using ifstream for this, and I can tell if it opened or not. But if
it doesn't open, how do I tell whether the file exists or not?
Here's what I have so far:
code:
ifstream foo();
foo.open(filename);
if(foo.is_open()){
// It's open...read it.
}else if(BAR){ // file does not exist
// handle file does not exist case
}else{
// complain to user that you can't open the file
}
So I need to know what I can put in place of BAR.
Can I trust the value of errno in this case? Is BAR "(errno==ENOENT)"?
I need the same code working in VC++ and unix/g++, so I'm looking for a
platform-agnostic solution, if one exists.
--Rob