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 />换行符转换为文本框中的换行符呢?下面这几个方 ...
随机推荐
- Tesseract5.0训练字库,提高OCR特殊场景识别率,合并字库(二)
一.准备工作 需要的文件 tif文件和box文件. 如果你打标打好了,但是是分批次打标的,那么可以合并字库,我们最初只需要 tif 和 box 文件,如下: 二.生成对应的 .tr 训练文件 根据不同 ...
- SpringMvc错误:HTTP Status 500 - Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is n
HTTP Status 500 - Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemExc ...
- Spring之使用注解实例化Bean并注入属性
1.准备工作 (1)导入jar包 除了上篇文章使用到的基本jar包外,还得加入aop的jar包,所有jar包如下 所需jar包 (2)配置xml <?xml version="1.0& ...
- Linux查看当前目录下所有文件中包含map的行记录
find yaochi_e.prm |xargs grep -ri "map" grep -n "map" *.prm|grep -v "\-\-ma ...
- C++ 数组动态分配
数组的动态内存分配 #include <iostream> //一维数组 void oneDimensionalArray() { //定义一个长度为10的数组 int* array = ...
- 通过利用immutability的能力编写更安全和更整洁的代码
通过利用immutability的能力编写更安全和更整洁的代码 原文:Write safer and cleaner code by leveraging the power of "Imm ...
- django之csrf_exempt解决跨域请求的问题
一: from django.views.decorators.csrf import csrf_exempt # 获取微信返回的code信息 @csrf_exempt def wechat_auth ...
- flask之表单
一:表单 表单用于注册,修改用户数据等场景. flask-wtf提供了一个包,可以创建表单:pip install flask-wtf 为了防止跨域请求,flask_wtf自己生成一个秘钥,用秘钥生成 ...
- sed 搜索并替换
find . -type f -exec sed -i "s/std=c++11/std=c++14/g" {} \; 搜索当前目录下的文件,把std=c++11替换成std=c+ ...
- web框架之初识Django
目录 一.web框架 1.1什么是web框架 1.2自制的简易web框架 1.3三大主流web框架简介 Django Flask Tornado 1.4动态网页与静态网页 二.初识Django框架 2 ...