fopen后只能读到部分文件问题解决,文本方式vs二进制方式
来源:互联网 发布:上海行知教育怎么样 编辑:程序博客网 时间:2024/06/05 20:06
在windows下经常有人遇到,fopen打开文件后,读取文件内容,读到一半的就收到EOF的问题。
其根源在于打开的方式选择了文本方式而未选择二进制方式。
在windows系统上这是有区别的,如果不加b,读取到第一个’\0’就会终止了。b –按二进制文件读取。
fp=fopen("D:\1.txt","rb");DESCRIPTIONThe 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.)
0 0
- fopen后只能读到部分文件问题解决,文本方式vs二进制方式
- fopen:文本和二进制方式打开 ZZ
- fopen按文本方式打开文件和按二进制方式打开文件的区别
- fopen等:文本方式和二进制方式打开文件的区别
- fopen文件方式与二进制方式打开文…
- fopen打开文件方式
- fopen打开文件方式
- 文本方式读写文件和以二进制方式
- C语言文本方式和二进制方式打开文件区别
- C语言文本方式和二进制方式打开文件区别
- C语言文本方式和二进制方式打开文件区别
- 文本与二进制方式打开文件的区别
- 文本与二进制方式打开文件的区别
- 文本与二进制方式打开文件的区别
- 文本与二进制方式打开文件的区别
- 文本与二进制方式打开文件的区别
- 文本与二进制方式打开文件的区别
- 文本与二进制方式打开文件的区别
- C#正则表达式 解析html+table tr td 内容
- windows下bat批处理实现守护进程(有日志)
- JavaScript语言基础7---函数的综合练习
- linux as4下安装oracle10g终结版
- 02 The TensorFlow Way(3)
- fopen后只能读到部分文件问题解决,文本方式vs二进制方式
- XML的生成与解析
- 开源软件expect软件安装
- Cocos2d-x:学习笔记(2017.05.12更新)
- 4-7 在一个数组中实现两个堆栈 (20分) PTA
- 下篇:Fusion of LiDAR 3D Points Cloud with 2D Digital Camera Image/3D点云与2D数字图像的融合
- java多线程 ---- 停止线程
- 奇偶位交换
- JSP自己写一个服务器