论操作非文本文件时,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. [antd-design-pro] mock 数据(post,request不一致)Sorry, we need js to run correctly!

    Sorry, we need js to run correctly! 可能问题: mock数据 api  和  request  api 不一致 'POST /api/banners/left'   ...

  2. 反向代理&集线器和交换机的区别&广播地址&seq与ack的区别

    反向代理服务器: 当一个代理服务器能够代理外部主机访问内部网络时,这种代理服务的方式称为反向代理服务,该服务器被称为反向代理服务器. 集线器与交换机的区别: 集线器和交换机都是起到端口转发的作用,不同 ...

  3. 基于ROS和beaglebone的串口通信方式,使用键盘控制移动机器人

    一.所需工具包 1.ROS键盘包:teleop_twist_keyboard  2.ROS串口通讯包:serial $ cd ~/catkin_ws/src $ git clone https://g ...

  4. 将Bdd100k数据集转为CoCo数据集

    小可爱,加油噻~ 添加上级目录 import sys sys.append('../..') 这样 from ... import 就会把加入的路径要扫描哒 os.walk() 方法用于通过在目录树中 ...

  5. MySQL更新命令_UPDATE

    创建测试表 mysql> CREATE TABLE `product` ( -> `proID` ) NOT NULL AUTO_INCREMENT COMMENT '商品表主键', -& ...

  6. poj2142 The Balance

    poj2142 The Balance exgcd 应分为2种情况分类讨论 显然我们可以列出方程 ax-by=±d 当方程右侧为-d时,可得 by-ax=d 于是我们就得到了2个方程: ax-by=d ...

  7. Java爬虫模拟登录——不给我毛概二的H某大学

    你的账号访问太频繁,请一分钟之后再试! 从大一开始 就用脚本在刷课 在专业课踢的只剩下一门C#的情况下 活活刷到一周的课 大二开始教务系统多了一个非常**的操作 退课池 and 访问频繁缓冲 难道,我 ...

  8. opencv学习之路(21)、模板匹配及应用

    一.模板匹配概念 二.单模板匹配 #include "opencv2/opencv.hpp" #include <iostream> using namespace s ...

  9. 解决多个div左浮动后不换行问题

    问题描述:我这里有多个li 让其左浮动,并且有序没有间隙的排列,就出现了中间空隙的问题: 解决办法:让每一个的第1个元素加上 clear:both属性,我这里每一行有2个,所以是: .b li:nth ...

  10. esay-ui学习笔记(一)

    JavaScript prototype用法 prototype 属性使您有能力向对象添加属性和方法. object.prototype.name=value <script type=&quo ...