# File I/O problems

## Recommended Posts

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[i],200,'*'); //taking in the file contents
}
fBookmarkInfo.close();
}
}
Everything compiles correctly but when it comes to runtime i get this error: 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

##### Share on other sites
Try checking if you have actually opened the file by checking is_open()

##### Share on other sites
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

##### Share on other sites
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.

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627638
• Total Posts
2978330

• 10
• 12
• 22
• 13
• 34