1

I've narrowed my code down, and I found the source of the problem, it's when I open a file. The file does exists, and I don't get any warning or errors when compiling.

int main(int argc, const char* args[]) 
{
    cout << "Wellcome" << endl;
    cout << args[1];
    ifstream exists(args[1]);
    if(!exists)
    {
        printf("FILE NOT FOUND");
        return 1;
    }
    exists.close();
    ifstream* in;
    in->open(args[1],ios::binary|ios::in);
    //do stuff
    in->close();
    return 0;
}
NullData
  • 394
  • 2
  • 8
  • There is absolutely no need to use a pointer to an `ifstream`. Let the class do its job by allocating it with automatic storage duration and read up on [RAII](http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization) – Ed S. Jun 14 '12 at 19:04

1 Answers1

2

You have created a pointer to an ifstream object, but you never allocated an ifstream for it to point to. To fix this, consider just stack-allocating it:

ifstream in;
in.open(args[1],ios::binary|ios::in);
//do stuff
in.close();

In general, you usually don't need to dynamically allocate objects unless you want them to outlive the function that created them.

Hope this helps!

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065