C++ File Binary
论操作非文本文件时,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的更多相关文章
- 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" ...
- 【system.file】使用说明
对象:system.file 说明:提供一系列针对文件操作的方法. 注意:参数中的filePath 均为相对网站根目录路径 目录: 方法 返回 说明 system.file.exists(filePa ...
- Codeforces Gym 100431B Binary Search 搜索+组合数学+高精度
原题链接:http://codeforces.com/gym/100431/attachments/download/2421/20092010-winter-petrozavodsk-camp-an ...
- nodejs进阶(4)—读取图片到页面
我们先实现从指定路径读取图片然后输出到页面的功能. 先准备一张图片imgs/dog.jpg. file.js里面继续添加readImg方法,在这里注意读写的时候都需要声明'binary'.(file. ...
- nodejs创建http服务器
之前有简单介绍nodejs的一篇文章(http://www.cnblogs.com/fangsmile/p/6226044.html) HTTP服务器 Node内建有一个模块,利用它可以很容易创建基本 ...
- Node.js配合node-http-proxy解决本地开发ajax跨域问题
情景: 前后端分离,本地前端开发调用接口会有跨域问题,一般有以下3种解决方法: 1. 后端接口打包到本地运行(缺点:每次后端更新都要去测试服下一个更新包,还要在本地搭建java运行环境,麻烦) 2. ...
- Linux 下编译openjdk
操作系统ubuntu14.04 openjdk版本 7u4 openjdk7u4可以在https://jdk7.java.net/source.html下载 一.构建编译环境 sudo apt-g ...
- nodeJS基础08:读取图片
1.读取图片 //server.js var http = require("http"); var readImage = require("./readImage&q ...
- iSight集成Adams/View:Simcode
虽然iSight有Adams/View接口,但对Adams的版本有限制.下面使用iSight的simcode,就可以支持任意版本的Adams了. Adams模型如下: 1. 编写cmd文件 file ...
随机推荐
- 单源最短路——Dijkstara算法
算法基本思想:每次找到离源点最近的一个顶点,然后以该顶点为中心进行扩展,最终得到源点到其余所有点的最短路径. 1.将所有的顶点分为两个部分:已知最短路程的顶点集合P和未知最短路径的顶点集合Q 2.设置 ...
- flutter 常用插件
audio_recorder: any #录音.播放 flutter_sound: ^1.1.5#录音 dropdown_menu: ^1.1.0#下拉菜单 simple_permissions:#权 ...
- Python3 tkinter基础 Menu Frame 创建右键菜单
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Lintcode482-Binary Tree Level Sum-Easy
482. Binary Tree Level Sum Given a binary tree and an integer which is the depth of the target level ...
- JS 单线程
js单线程阻塞实例setTimeout(function () { while (true) { } }, 1000);setTimeout(function () { alert('end 2'); ...
- Openstack官网文档简介
OpenStack documentation相关文档见 docs.openstack.org. 主要包含这些方面的文档: Installation Guides Deployment Guides ...
- pta-3
一:实验代码 include <stdio.h> int main() { char ch; int income=0; int unhappy, sad, glad; unhappy = ...
- recon工具解读
recon 是ferd 大神 释出的一个 用于生产环境诊断Erlang 问题的一个工具, 不仅仅是对Erlang stdlib 接口的封装, 还有memory fragmentation 相关的函数. ...
- 20165309 2017-2018-2《Java程序设计》课程总结
20165309 2017-2018-2<Java程序设计>课程总结 一.每周作业链接汇总 预备作业1:我期望的师生关系 预备作业2:技能学习经验与C语言 预备作业3:Linux安装及学习 ...
- 若依项目整合eCharts实现图表统计功能
eCharts是一款强大的图表统计工具,具体介绍可查看其官网 http://echarts.baidu.com/echarts2/index.html 下面记录一下如何在若依项目中使用eCharts. ...