zoukankan      html  css  js  c++  java
  • 抛出错误Debug Assertion Failed!

      出现这种情况很可能是使用了野指针,比如某个指针指向一个局部变量,而在该变量作用域外使用该指针引用了该对象。
      Assertion 是断言,用于假定某个条件肯定会满足,在debug模式下,当该条件不满足时则发生阻塞而弹出该对话框;在release下会忽略断言。

      我不知道具体原因,但是我找到了一种解决办法:选择Build→Clean,重新编译就可以了

      expression:stream !=NULL

      如果fopen()后返回的是NULL;就不能调用fclose()了;

      用fopen()获得的文件句柄不是NULL,那么就需要用fclose()来关闭它。如果是NULL则不需要
        null就表示你打开文件失败了,根本都没有成功的访问文件,也就不存在对数据有什么损坏的可能。不需要关闭。

     

    在定义FILE * fp 之后,fopen的用法是:

    fp = fopen(filename,"w")。

    而对于fopen_s来说,还得定义另外一个变量errno_t err,然后

    err = fopen_s(&fp,filename,"w")。

    返回值的话,对于fopen来说,打开文件成功的话返回文件指针(赋值给fp),打开失败则返回NULL值;对于fopen_s来说,打开文件成功返回0,失败返回非0。

    在vs编程中,经常会有这样的警告:warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use_CRT_SECURE_NO_WARNINGS. See online help for details.  是因为  fopen_s比fopen多了溢出检测,更安全一些

  • 相关阅读:
    [LeetCode] 582. Kill Process
    [LeetCode] 686. Repeated String Match
    [LeetCode] 341. Flatten Nested List Iterator
    [LeetCode] 404. Sum of Left Leaves
    [LeetCode] 366. Find Leaves of Binary Tree
    [LeetCode] 1485. Clone Binary Tree With Random Pointer
    [LeetCode] 459. Repeated Substring Pattern
    [LeetCode] 565. Array Nesting
    [LeetCode] 679. 24 Game
    [LeetCode] 364. Nested List Weight Sum II
  • 原文地址:https://www.cnblogs.com/baoxiaofei/p/4296192.html
Copyright © 2011-2022 走看看