File I/O problems

Started by
2 comments, last by Ezbez 16 years, 10 months ago
Hey all, ive this function in a DirectX application:
void ReadBookmarkContent()
{
	
	int i=0;
	
	std::fstream fBookmarkInfo(books\\bookmarks.txt");

	{
	for(i=0;!fBookmarkInfo.eof();i++)
	{
	fBookmarkInfo.getline(cBookmarkInfo,200,'*'); //taking in the file contents
	}
	fBookmarkInfo.close();
	}	
}
Everything compiles correctly but when it comes to runtime i get this error: Image Hosted by ImageShack.us Anyone got a idea why it happens? ive got a very similar function to this in another place that works fine. the character array is defined as: char cBookmarkInfo[40][200]; Which is a global variable, Further info the error, it occurs here in istream:

_CATCH_IO_END
			}

	---->	*_Str = _Elem();	// add terminating null character
		_Myios::setstate(_Chcount == 0 ? _State | ios_base::failbit : _State);
		return (*this);
		}
And call stack says:

>	msvcp80d.dll!std::basic_istream<char,std::char_traits<char> >::getline(char * _Str=0x0093c188, int _Count=200, char _Delim='*')  Line 648 + 0x3 bytes	C++
:O, thanks for your help Chett
Chett - "I look forward to helping all of you one day, but right now im just a noob learning his way through the perils of game Development."
Advertisement
Try checking if you have actually opened the file by checking is_open()
regards/thallishI don't care if I'm known, I'd rather people know me
You want to know what the problem was? I wrote the file name as bookmark.txt and it was allready a txt format so the real file name was bookmark.txt.txt, and this got me so fustrated last night lol.

Thanks for the help,
Chett
Chett - "I look forward to helping all of you one day, but right now im just a noob learning his way through the perils of game Development."
Hehe. Any programmer should have Windows show file extensions. FYI, open a folder then go to Tools->Folder Options->View Then uncheck 'Hide extensions for known file types'. No more of that problem!

But as thallish said, you should probably assert or something that the file is open.

This topic is closed to new replies.

Advertisement