fopen后只能读到部分文件问题解决,文本方式vs二进制方式
2017-05-01 08:31
531 查看
在windows下经常有人遇到,fopen打开文件后,读取文件内容,读到一半的就收到EOF的问题。
其根源在于打开的方式选择了文本方式而未选择二进制方式。
在windows系统上这是有区别的,如果不加b,读取到第一个’\0’就会终止了。b –按二进制文件读取。
其根源在于打开的方式选择了文本方式而未选择二进制方式。
在windows系统上这是有区别的,如果不加b,读取到第一个’\0’就会终止了。b –按二进制文件读取。
fp=fopen("D:\1.txt","rb"); DESCRIPTION The fopen() function opens the file whose name is the string pointed to by path and associates a stream with it. The argument mode points to a string beginning with one of the following sequences (possibly followed by additional characters, as described below): r Open text file for reading. The stream is positioned at the beginning of the file. r+ Open for reading and writing. The stream is positioned at the beginning of the file. w Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file. w+ Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file. a Open for appending (writing at end of file). The file is created if it does not exist. The stream is positioned at the end of the file. a+ Open for reading and appending (writing at end of file). The file is created if it does not exist. The initial file position for reading is at the beginning of the file, but output is always appended to the end of the file. The mode string can also include the letter 'b' either as a last character or as a character between the characters in any of the two-character strings described above. This is strictly for com‐ patibility with C89 and has no effect; the 'b' is ignored on all POSIX conforming systems, including Linux. (Other systems may treat text files and binary files differently, and adding the 'b' may be a good idea if you do I/O to a binary file and expect that your program may be ported to non-UNIX environments.)
相关文章推荐
- [置顶] fopen等:文本方式和二进制方式打开文件的区别
- fopen按文本方式打开文件和按二进制方式打开文件的区别
- VS使用中(sdf和ipch)临时文件放置问题解决
- Android Studio中项目NDK原生部分整合方式(相对路径头文件找不到的问题)
- Eclipse中改变编码方式及解决部分乱码问题
- 解决vs2015使用fopen、fprintf等函数报错的问题
- ubuntu 7.10 的 evince 看部分PDF文件乱码问题解决
- php5.6关于curl以@方式上传文件的变化及解决七牛上传时报file is not specified in multipart的问题
- 以上的文章是我解决这样一个问题时候的大致的思路: 把Matlab读取二进制文件的函数变成VBA读取二进制文件,实现同样的功能
- 以文本方式上传二进制文件的PHP程序
- 解决vs创建或打开C++浏览数据库文件*.sdf时发生错误的问题
- VS2012 每次编译程序都会出现”无法查找或打开 PDB 文件“问题解决方案
- 你碰到过双击exe文件或桌面快捷方式没反应的情况吗;一段代码解决问题:
- C语言文本方式和二进制方式打开文件区别
- fopen:文本和二进制方式打开 ZZ
- VS2013中如何解决error C4996: 'fopen'问题
- VC 读取文本文件内容,中文乱码的问题解决
- 文件读写: 二进制方式和文本方式的区别
- 文件读写:fwrite与fprintf的区别(即二进制方式和文本方式的区别)
- 文件读写:fwrite与fprintf的区别(即二进制方式和文本方式的区别)