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 ...
随机推荐
- 《CSS世界》读书笔记(十)
<!-- <CSS世界>张鑫旭著 --> 温和的padding属性 因为默认的box-sizing是content-box,所以使用padding会增加元素的尺寸. 尺寸表现对 ...
- linux命令之pssh命令
查看一下pssh命令的帮助文档: [root@test2 ~]# pssh --version [root@test2 ~]# pssh --help Usage: pssh [OPTIONS] co ...
- APScheduler(Python化的Cron)使用总结 定时任务
APScheduler(Python化的Cron)使用总结 简介 APScheduler全程为Advanced Python Scheduler,是一款轻量级的Python任务调度框架.它允许你像Cr ...
- CSS 边框样式
CSS 边框样式 直线边框样式 <html> <body> <!-- border: 1px 边框像素为1.solid red 边框样式以及边框颜色 --> < ...
- Docker Compose 一键部署Nginx代理Tomcat集群
Docker Compose 一键部署Nginx代理Tomcat集群 目录结构 [root@localhost ~]# tree compose_nginx_tomcat/ compose_nginx ...
- Linux下执行Oracle的sql脚本
(1) 启动监听: Root用户登录后,输入: $su – oracle 回车(Oracle为Oracle数据库安装用户,必须有横杠: - ) 启动监听: $lsnrctl start --启动 $ ...
- Linux查看服务器硬件配置命令
一.查看服务器硬件信息 dmidecode|grep "System Information" -A9|egrep "Manufacturer|Product|Seria ...
- 用python写MapReduce函数——以WordCount为例
尽管Hadoop框架是用java写的,但是Hadoop程序不限于java,可以用python.C++.ruby等.本例子中直接用python写一个MapReduce实例,而不是用Jython把pyth ...
- Java 批量导入大量数据
项目上线测试.产品说导入太慢了,一样的数据量另外一个系统只需要1分钟,我们要5分钟.... 开始以为是因为POI在解析07版本的Excel时候,因为数据量太多所以慢了,后面看下日志,发现是在入库的时候 ...
- 浅谈JS中的typeof和instanceof的区别
JS中的typeof和instanceof常用来判断一个变量是否为空,或者是什么类型. typeof typeof运算符返回一个用来表示表达式的数据类型的字符串. typeof一般返回以下几个字符串: ...