C++: fread() causing assertion error?
I have an error cause by fread()
and it says:
File: f:\ dd\vctools\ crt_bld\ self_x86\ crt\ src\fread.c
Line: 102
Expression: (stream != NULL)
For information on how your program can cause an assertion
failure, see the Visu开发者_开发百科al C++ documentation on asserts.
(Press Retry to debug the application)
What should I do? I have already include <stdio.h>
in my program. I'm currently developing my project using Visual C++ MFC.
Expression: (stream != NULL)
explains it all.
You're passing a NULL
stream to fread
and you should not.
Have you verified that you have a proper FILE object to send to fread? Try to check if it is null before using it. Also check out that documentation on assert, it's not about what files you have #included or not. This is a runtime error.
The function fread()
takes as the an argument a FILE*
:
size_t __cdecl fread(
void *buffer,
size_t elementSize,
size_t count,
FILE *stream
)
The FILE*
you are sending it is NULL. you should debug your program and find out why that is so.
You could have found this information on your on, the same way I did, by opening the file f:\ dd\vctools\ crt_bld\ self_x86\ crt\ src\fread.c
in your computer and looking what it does on line 102.
Have you tried the (Press Retry to debug the application)
part of the message.
If you enter the debugger, you will likely end up at the assert() and can check the call stack to find where the call to fread comes from. Then figure out why the FILE* is null there! Perhaps a failed call to fopen?
精彩评论