# C++ file I/O

## Recommended Posts

Cacks    179
Hi guys, I have created methods for saving and loading my objects to and from disk. They work fine. I'm using VC++ .Net 2003, but I'm using std ifstream & ofstream. I'm wondering what kinds of exceptions can this throw? I'm especially interested in how I would find if the file intended to be loaded does not exist? How would I deal with this error. Thanks for any help given!

##### Share on other sites
dave    2187
Hey bud,

What i would do here is simply try and open the file as you prolly already are, but then immediately check the whether it is open or not, like this:
if ( myFile.is_open() ){  // blah}

I'm not particularly expereince with C++ files but i believe there is no need to worry about exceptions here. If it isn't open then it isn't open.

Hope that helps,

Dave

##### Share on other sites
Cacks    179
Hey, thanks for that!