Initializing a file

I keep geting this errer, but I thought I was initializing it.
Run-Time Check Failure #3 - The variable 'file' is being used without being initialized.
1
2
3
4
	ifstream *file;
	for ( list<string>::const_iterator Iter = fNames.cbegin(); Iter != fNames.cend(); Iter++ )
	{
		file->open( ( *wd + "\\Definitions\\" + *Iter ).c_str() );
ifstream *file; just gives you a pointer (which is not initialized). Before you can use it sensibly, it must point to an object of type ifstream.

Why do you want to use a pointer for this?

1
2
3
4
5
6
        //ifstream *file;
        ifstream file ;
	for ( list<string>::const_iterator Iter = fNames.cbegin(); Iter != fNames.cend(); Iter++ )
	{
		//file->open( ( *wd + "\\Definitions\\" + *Iter ).c_str() );
                file.open( ( *wd + "\\Definitions\\" + *Iter ).c_str() );
Thanks.
Topic archived. No new replies allowed.