fread fwrite文本模式读写回车换行符 自动转换问题
fread 会把\r\n(0d0a)替换为\n
fwrite 会把\n替换为\r\n(0d0a),\r\n会变成\r\r\n(0d0d0a)
今天在写一个日志类,用于打印服务程序的信息。
FILE *file = fopen(log_file_name,"a+");
if (!file)return;
fwrite("\r\n",3,file);//这里不是原始代码,只用来说明问题
然后用winhex软件查看了十六进制的数据,结果发现\r\n对应的十六进制为0D 0D 0A。
Remarks
The fwrite function writes up to count items, of size length each, from buffer to the output stream.
The file pointer associated with stream (if there is one) is incremented by the number of bytes actually written.
If stream is opened in text mode, each carriage return is replaced with a carriage-return – linefeed pair.
The replacement has no effect on the return value.
下面是在线-MSDN: 修正了上面的错误
Remarks
The fwrite function writes up to count items, of size length each, from buffer to the output stream. The file pointer associated with stream (if there is one) is incremented by the number of bytes actually written. If stream is opened in text mode, each line feed is replaced with a carriage return-line feed pair. The replacement has no effect on the return value.
When stream is opened in Unicode translation mode—for example, if stream is opened by calling fopen and using a mode parameter that includes ccs=UNICODE, ccs=UTF-16LE, or ccs=UTF-8, or if the mode is changed to a Unicode translation mode by using _setmode and a mode parameter that includes _O_WTEXT, _O_U16TEXT, or _O_U8TEXT—buffer is interpreted as a pointer to an array of wchar_t that contains UTF-16 data. An attempt to write an odd number of bytes in this mode causes a parameter validation error.
Because this function locks the calling thread, it is thread-safe. For a non-locking version, see _fwrite_nolock.
备注
Fwrite函数将每个项的大小从缓冲区写入到输出流, 并对其进行计算。 与流关联的文件指针 (如果有) 以实际写入的字节数为增量递增。
如果在文本模式下打开流, 则会将每个换行符替换为回车换行符对。 该替换不会影响返回值。
fread fwrite文本模式读写回车换行符 自动转换问题的更多相关文章
- Git坑换行符自动转换 [转载]
转自https://www.cnblogs.com/zjoch/p/5400251.html 源起 一直想在 GitHub 上发布项目.参与项目,但 Git 这货比较难学啊.买了一本<Git 权 ...
- GitHub 第一坑:换行符自动转换
源起 一直想在 GitHub 上发布项目.参与项目,但 Git 这货比较难学啊.买了一本<Git 权威指南>,翻了几页,妈呀,那叫一个复杂,又是 Cygwin 又是命令行的,吓得我不敢学了 ...
- github 换行符自动转换功能
最近想把自己的一个Qt工程同步到github上,但是当自己把代码从仓库中签出来的时候编译的时候总是出现一些很奇葩的错误,一开始以为是源文件编码的问题,改了编码以后问题还是没有解决,我比较了一下两个工程 ...
- git换行符自动转换导致整个文件被修改的解决方案
不少开发者可能遇到过这个问题:从git上拉取服务端代码,然后只修改了一处地方,准备提交时,用diff软件查看,却发现整个文件都被修改了.这是git自动转换换行符导致的问题. 原因 不同操作系统使用的换 ...
- 【aardio】回车换行符
回车换行符 在计算机还没有出现之前,有一种叫做电传打字机(Teletype Model 33)的玩意,每秒钟可以打10个字符.但是它有一个问题,就是打完一行换行的时候,要用去0.2秒,正好可以打两个字 ...
- linux与windows回车换行符的区别
转自:http://www.cnblogs.com/dartagnan/archive/2010/12/14/2003499.html “回车”(carriage return)VS “换行”(li ...
- 【转】去掉Sqlite3 数据库中的前后回车换行符(newline)
原文: http://www.blogjava.net/pts/archive/2013/06/10/400... 时间: 2013-06-10 转自:http://www.ityuedu.com/a ...
- ruby正则匹配回车换行符
如果你使用/^.*$/这种正则是匹配不到回车换行符的. 所以应该像下面这么写: /^[\s\S]*$/
- 将html中的br换行符转换为文本输入中的换行符(转)
PHP中的有个非常好的函数:nl2br(),将文本框中的换行转换为HTML页面的<br />,但是如何实现将html中的<br />换行符转换为文本框中的换行符呢?下面这几个方 ...
随机推荐
- Mac入门--Apache/Php/Mysql的开启关闭
注意:mac自带apache环境和PHP环境 一 php服务的启动和关闭 php-fpm 启动 sudo php-fpm php-fpm 关闭 1 查看php-fpm端口是否在被php-fpm进程 n ...
- jquery悬停和移出事件
$('#hides').mouseover(function () { alert("sdfdsf")}).mouseout(function () { alert("啊 ...
- mongoDB关系型数据库的对比
一.基本操作 1.mongoDB和关系型数据库对比 对比项 mongoDB mysql oracle 表 集合list 二维表 表的一行数据 文档document 一条记录 表字段 键key 字段fi ...
- bootstrap复习
菜单 <div class="row">下拉菜单/分裂菜单</div> <div class="dropdown btn-group&quo ...
- Anaconda 安装及Python 多版本间切换
安装 Anaconda 安装anaconda 安装较为简单,这里参考官方文档:https://docs.continuum.io/anaconda/install/linux.html 在文件目录下执 ...
- Oracle 11g+Windows10 x64安装、配置过程记录
备注:本想在自己电脑上安装个oracle练习用,但是害怕安装过程中出现问题,而oracle的卸载又是出了名的麻烦,所以用虚拟机搭建了一个跟本机一样的系统,同时记录下安装的每一步. 环境:windows ...
- linux tcp/ip 调优
sysctl 变量修改方法:sysctl –a 使用 sysctl 命令修改系统变量,和通过编辑 sysctl.conf 文件来修改系统变量两种.但并不是所有的 变量都可以在这个模式下设定. 注:sy ...
- 脚本_修改 Linux 系统的最大打开文件数量
#!bin/bash#作者:liusingbon#功能:修改 Linux 系统的最大打开文件数量#追加两行配置参数到文件/etc/security/limits.conf的末尾,修改最大打开文件数量为 ...
- Codeforces917E
//#include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #i ...
- 体验一把haskell
这几天做到PAT一道比较数据大小的题PAT1065,题目不难,应该说是一道送分题,就是开数组,然后模拟人工计算的过程进行计算,再比较下就行.做完之后,联想到haskell的Integer类型是无限大的 ...