将数组写入txt读出后数据出错
来源:互联网 发布:eclipse怎么编写java 编辑:程序博客网 时间:2024/06/05 20:32
最近使用fwrite将缓冲区的内容写入文件,发现写入的字节数与预期的不一致,后来发现是打开文件时fopen使用的mode是“w”,改为“wb”问题解决。 查看BCB的帮助文档发现: The mode string used in calls to fopen is one of the following values: Value Description r Open for reading only. w Create for writing. If a file by that name already exists, it will be overwritten. a Append; open for writing at end-of-file or create for writing if the file does not exist. r+ Open an existing file for update (reading and writing). w+ Create a new file for update (reading and writing). If a file by that name already exists, it will be overwritten. a+ Open for append; open (or create if the file does not exist) for update at the end of the file. To specify that a given file is being opened or created in text mode append a t to the mode string (rt, w+t, and so on). Similarly to specify binary mode append ab to the mode string (wb, a+b, and so on).fopen also allows the t or b to be inserted between the letter and the+ character in the mode string; for example rt+ is equivalent tor+t. If a t or b is not given in the mode string the mode is governed by the global variable_fmode. If _fmode is set to O_BINARY files are opened in binary mode. If_fmode is set to O_TEXT they are opened in text mode. TheseO_... constants are defined in fcntl.h. 原来BCB中fopen的“w”模式默认为“wt”,以文本方式打开文件。 二进制数据中难免有一些特殊字符,以文本方式打开后,fwrite每遇到一个0x0A就会在前面加一个0x0D,造成上面的问题。 Windows以“\r\n”为换行符
阅读全文
0 0
- 将数组写入txt读出后数据出错
- TxT写入 读出
- matlab 将数组写入txt
- 编写简单一个程序 将一个长整型数据 写入字节数组中,在从字节数组中读出来
- matlab将二维数组写入txt文件
- MATLAB 将数组一列写入 .txt 文件
- 写入、读出数据
- 将Excel数据写入到TXT中
- 将数据写入.txt文件中
- 将list数据写入到txt中
- 使用java语言将数组中的数据写入txt文件,然后读取
- C/C++将文txt本中的数据字符串写入数组
- 把txt文本数据写入二维数组
- C++ 将数据写入链表,将链表写入文件,再将文件中的内容读出
- 将硬盘中两个TXT文件读出来,并写入另一个文件
- php将数据写入数组
- java简单读出和写入txt文件
- 【C++】Mat型数据写入txt文件并可用标签进行搜索读出
- linux修改权限
- 浙大PAT甲级-1029
- grunt官网教程(中文版)
- Android之CardView的使用
- 详解Response、Request二
- 将数组写入txt读出后数据出错
- poj 3461 kmp算法
- 代理模式
- SpringBoot(七):SpringBoot整合Swagger2
- 1057. 数零壹(20)
- 并发AQS同步器
- TCP/IP协议之IP协议
- POJ3159 最大差距(差分约束系统) (K)
- PAT b1031-b1035题解