开发者

Why does my code crash on ifstream.close? (C++, VS2010) [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Why would fclose hang / deadlock? (Windows)

when i call .close i get a crash.

Why does my code crash on ifstream.close? (C++, VS2010) [duplicate]

What i do is save a file, close it and load it immediately. This is for debugging reasons to see if my serialization code is working (it has many checks and they all pass)

I did some debugging and i cant figure out what may cause it. What i notice is

  • It crashes on a specific file
  • Running the file alone wont crash
  • Removing a multiple file will decrease the chance of it from crashing (but i am unsure if it has relevant). From 100% to 50% or 30% depending on how many i remove.
  • The less files i have the less likely it will happen. But it always happens on that specific file no matter the amount of files
  • Other files crash as well but in a different bat series

But whats bothering me is - The file seems to load properly. I put in a debug counter and it is incremented the correct amount of times. - The file handle is alive f开发者_如何学Pythonor only one function. The function loads it closes the file and returns the parsed data. Why is it affected by other files in the bat series

In release mode if i run the files in the VS IDE its fine. When i press ctrl F5 to run outside it crashes. But running the single file with release outside of the IDE is fine as well.

I'm very confused.


As Ben Voigt says, it's probably a problem elsewhere in the program (perhaps in a seemingly unrelated place), not ifstream::close() itself. Stack overflow (the problem, not this site), wayward pointer, writing past the end of an array -- these are common causes of such problems.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜