简体   繁体   English

C ++:fread()导致断言错误?

[英]C++: fread() causing assertion error?

I have an error cause by fread() and it says: 我有一个由fread()引起的错误,它说:

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 Visual C++ documentation on asserts.
(Press Retry to debug the application)

What should I do? 我该怎么办? I have already include <stdio.h> in my program. 我的程序中已经包含了<stdio.h> I'm currently developing my project using Visual C++ MFC. 我目前正在使用Visual C ++ MFC开发我的项目。

Expression: (stream != NULL) explains it all. Expression: (stream != NULL)解释了这一切。

You're passing a NULL stream to fread and you should not. 您正在传递NULL流以进行fread ,但您不应该这样做。

Have you verified that you have a proper FILE object to send to fread? 您是否已验证要发送给fread的FILE对象正确? Try to check if it is null before using it. 使用它之前,请尝试检查它是否为null。 Also check out that documentation on assert, it's not about what files you have #included or not. 还要检查有关断言的文档,这与是否包含#include的文件无关。 This is a runtime error. 这是运行时错误。

The function fread() takes as the an argument a FILE* : 函数fread()FILE*作为参数:

size_t __cdecl fread(
    void *buffer,
    size_t elementSize,
    size_t count,
    FILE *stream
)

The FILE* you are sending it is NULL. 您要发送的FILE*为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. 通过打开计算机中的文件f:\\ dd\\vctools\\ crt_bld\\ self_x86\\ crt\\ src\\fread.c并查看其在第102行上的工作,您可能会像在我以前一样找到此信息。

Have you tried the (Press Retry to debug the application) part of the message. 您是否尝试过消息的(Press Retry to debug the application)部分。

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. 如果进入调试器,则可能会到达assert()并检查调用堆栈以查找fread调用的来源。 Then figure out why the FILE* is null there! 然后找出为什么FILE *在那里为空! Perhaps a failed call to fopen? 也许fopen失败了?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM