二进制文件的打开方式

编程入门 行业动态 更新时间:2024-10-10 17:23:04
本文介绍了二进制文件的打开方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好我想打开读取和写入二进制文件(没有截断,没有附加)。我使用模式R + B。我没有得到任何编译错误,但是当读什么我写我得到垃圾值。任何想法。

Hi I want to open a binary file for both reading and writing(without truncating, not appending). I use mode "r+b". I get no compiling errors but when read what I have written I get garbage values. Any idea.

但是,如果我打开文件写(模式为世行)..写入in..close,然后打开该文件进行读取(模式为RB),a和读取它,然后它工作正常。

But if I open the file for writing(mode as "wb")..write into in..close it and then open the file for reading(mode as "rb") aand read from it ,then it works fine.

推荐答案

当你打开读/写模式的文件,如R +,W +,你需要确保你的文件指针指向一个有效的位置。 fseek的()这里是你的朋友。

When you open a file in read/write modes such as "r+", "w+", you need to make sure your file pointer points to a valid position. fseek() is your friend here.

此外,作为一个很好的做法,记得要经常从函数检查返回值。在这种情况下,也许你的FREAD()都失败了没有你注意到它。

Also, as a good practice, remember to always check returned values from functions. In this case, maybe your fread() have failed without you noticing it.

更多推荐

二进制文件的打开方式

本文发布于:2023-11-13 06:21:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583685.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式   二进制文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!