论操作非文本文件时,std::ios::binary的重要性

今天在读取图片文件的时候,根据图片数据的高宽对图片数据进行读取,但是出现了图片数据读取不完整,但是文件已经到达末尾的情况,中间想过read是否有问题,后来查阅函数说明发现这个std::ios::binary属性。

最后恍然大悟,如果不以二进制方式来读取文件,一些特殊控制字符会被直接过滤掉,从而导致读取提前结束的情况。

member constant stands for access
in * input File open for reading: the internal stream buffer supports input operations.
out output File open for writing: the internal stream buffer supports output operations.
binary binary Operations are performed in binary mode rather than text.
ate at end The output position starts at the end of the file.
app append All output operations happen at the end of the file, appending to its existing contents.
trunc truncate Any contents that existed in the file before it is open are discarded.

参考:http://www.cplusplus.com/reference/fstream/ifstream/open/

C++ File Binary的更多相关文章

  1. nodejs -- fs模块 ---> readFile 函数 1) fs.readFile(filename, "binary", function(error, file) 2) response.write(file, "binary");

    一:代码: 1.1 入口文件: index.js var server = require('./server'); var router = require("./router" ...

  2. 【system.file】使用说明

    对象:system.file 说明:提供一系列针对文件操作的方法. 注意:参数中的filePath 均为相对网站根目录路径 目录: 方法 返回 说明 system.file.exists(filePa ...

  3. Codeforces Gym 100431B Binary Search 搜索+组合数学+高精度

    原题链接:http://codeforces.com/gym/100431/attachments/download/2421/20092010-winter-petrozavodsk-camp-an ...

  4. nodejs进阶(4)—读取图片到页面

    我们先实现从指定路径读取图片然后输出到页面的功能. 先准备一张图片imgs/dog.jpg. file.js里面继续添加readImg方法,在这里注意读写的时候都需要声明'binary'.(file. ...

  5. nodejs创建http服务器

    之前有简单介绍nodejs的一篇文章(http://www.cnblogs.com/fangsmile/p/6226044.html) HTTP服务器 Node内建有一个模块,利用它可以很容易创建基本 ...

  6. Node.js配合node-http-proxy解决本地开发ajax跨域问题

    情景: 前后端分离,本地前端开发调用接口会有跨域问题,一般有以下3种解决方法: 1. 后端接口打包到本地运行(缺点:每次后端更新都要去测试服下一个更新包,还要在本地搭建java运行环境,麻烦) 2. ...

  7. Linux 下编译openjdk

    操作系统ubuntu14.04 openjdk版本 7u4 openjdk7u4可以在https://jdk7.java.net/source.html下载   一.构建编译环境 sudo apt-g ...

  8. nodeJS基础08:读取图片

    1.读取图片 //server.js var http = require("http"); var readImage = require("./readImage&q ...

  9. iSight集成Adams/View:Simcode

    虽然iSight有Adams/View接口,但对Adams的版本有限制.下面使用iSight的simcode,就可以支持任意版本的Adams了. Adams模型如下: 1. 编写cmd文件 file ...

随机推荐

  1. Linux服务器---百科mediawiki

    Mediawiki         Mediawiki是一个强大的维基软件,可以实现页面编辑.图像和多媒体管理. 1.下载mediawiki软件(“https://www.mediawiki.org/ ...

  2. /* * 有五个学生,每个学生有3门课的成绩,从键盘输入以上数据 *(包括学生号,姓名,三门课成绩),计算出平均成绩, *将原有的数据和计算出的平均分数存放在磁盘文件"stud"中。 */

    1.Student类:类中有五个变量,分别是学号,姓名,三门成绩 package test3; public class Student { private int num; private Stri ...

  3. java static语句的总结

    static 是静态方法,他的引用不需要对象,可以使用类名直接进行引用,当然也不需要this.      由于不需要对象,所以static方法内无法调用非static的方法或对象   至于为什么mai ...

  4. Android组件系列----Intent详解

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3 ...

  5. Ubuntu 16.04下vsftpd 安装配置实例

    从https://www.linuxidc.com/Linux/2017-06/144807.htm转载 第一步:安装VSFTPD sudo apt-get install vsftpd 安装完成后启 ...

  6. GIT 私有仓库 github项目提交失败 master -> master (non-fast-forward)

    https://blog.csdn.net/fightingforcv/article/details/52073182 https://blog.csdn.net/u014135752/articl ...

  7. Vue监听属性的变化

    监听属性的变化watch: { counter: function (nval, oval) { alert('计数器值的变化 :' + oval + ' 变为 ' + nval + '!') }}

  8. angular --- s3core移动端项目(二)

    product-ctrl.js angular.modules('myApp').controller('ProductCtrl',['$scope','$rootScope','$timeout', ...

  9. 利用Fiddler编写Jmeter接口测试

    利用Fiddler抓包APP应用接口,在Jmeter编写接口测试脚本 1.用Fiddler对Android用用进行抓包 Fiddler介绍: Fiddler是一款非常流行并且实用的http抓包工具,它 ...

  10. JVM ——知识总结(面试)

    1)JAVA语言是一种强语言 2)JAVA不允许使用指针访问内存,不允许使用指针数组访问内存 3)有自动收集垃圾的作用 4)方法调用时,会创建栈帧在栈中,调用完是程序自动出栈释放,而不是gc释放 5) ...