binary and out mode to open a file
When I use binary and out mode to open a exist file, and to modify the 4th and 8th byte data to 0x78, I found that the whole file will be rewrite, like below:
#include <fstream>
#include <iostream>
using namespace std; int main(int argc, char **argv)
{
fstream out;
out.open("./test.txt", ios_base::binary | ios_base::out); uint8_t data = 0x78; out.seekp(4, ios_base::beg);
out.write((char *)&data, 1); out.seekp(8, ios_base::beg);
out.write((char *)&data, 1); out.close();
return 0;
}
And the file original data is :
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
But the file modified is:
00 00 00 00 78 00 00 00 78
I have tried ios::app and ios::ate, the ios::app will out put my data at the end of the file and the skeep do not work.
Finally, I thought out that the file is just a out file, so the api will not see the original data of the file, so I should add the ios::in.
#include <fstream>
#include <iostream>
using namespace std; int main(int argc, char **argv)
{
fstream out;
out.open("./test.txt", ios_base::binary | ios_base::out | ios_base::in); uint8_t data = 0x78; out.seekp(4, ios_base::beg);
out.write((char *)&data, 1); out.seekp(8, ios_base::beg);
out.write((char *)&data, 1); out.close();
return 0;
}
And finally, I got the right data.
FF FF FF FF 78 FF FF FF 78 FF FF FF FF FF FF FF
binary and out mode to open a file的更多相关文章
- Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'系列一:
从库报这个错误:Got fatal error 1236 from master when reading data from binary log: 'Could not find first lo ...
- mysql从库Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'报错处理
年后回来查看mysql运行状况与备份情况,登录mysql从库查看主从同步状态 mysql> show slave status\G; *************************** . ...
- Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'
setup slave from backup i got error Got fatal error 1236 from master when reading data from binary l ...
- Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'系列三:重置主从同步
1:停止slave服务器的主从同步 stop slave; 2:对Master数据库加锁 flush tables with read lock; 3:备份Master上的数据 mysqldump - ...
- 主从同步遇到 Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'时怎么解决
首先遇到这个是因为binlog位置索引处的问题,不要reset slave: reset slave会将主从同步的文件以及位置恢复到初始状态,一开始没有数据还好,有数据的话,相当于重新开始同步,可能会 ...
- Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'系列二:reset slave
reset slave会清除从库的所有复制信息.一般应用场景:如切换为不同的Master, 主从重做等: 1. 命令在slave上执行,执行前一定要stop slave. 2. 执行reset sla ...
- 'Could not find first log file name in binary log index file'的解决办法
数据库主从出错: Slave_IO_Running: No 一方面原因是因为网络通信的问题也有可能是日志读取错误的问题.以下是日志出错问题的解决方案: Last_IO_Error: Got fatal ...
- Serialize and Deserialize Binary Tree
Design an algorithm and write code to serialize and deserialize a binary tree. Writing the tree to a ...
- [LintCode] Binary Tree Serialization
Design an algorithm and write code to serialize and deserialize a binary tree. Writing the tree to a ...
随机推荐
- Axis2开发WebService客户端 的3种方式
Axis2开发WebService客户端 的3种方式 在dos命令下 wsdl2java -uri wsdl的地址(网络上或者本地) -p com.whir.ezoffi ...
- java8学习笔记之lambda表达式
1.lambda表达式特点 lambda表达式可以理解为可传递的匿名函数的一种方式,无名称,但有参数列表和函数体以及返回类型,可能还有一个可抛出异常的列表. 2.lambda表达式基本语法 (para ...
- QtQuick多页面切换、多页面切换动画、多个qml文件数据交互
一.QtQuick多页面切换方法 (1)“隐藏法” 前一个视图visible设为false或者透明度opacity设为0,相当于“隐藏”了,实际还存在: 要显示的视图visible设为true或者透明 ...
- 用javaScript对页面元素进行显示和隐藏
将显示元素进行隐藏 用document.getElementById("ID名").hidden=ture;根据页面元素ID名获得页面元素值,进而将其属性设置成隐藏. 将隐藏元素进 ...
- List添加map,后添加的map覆盖前面的问题
List resultList = new ArrayList(); Map map = new HashMap(); while(rs.next()){ String userid = rs.get ...
- shell编程(一)之变量
变量:命名的内存空间 bash的变量种类: 根据变量的生效范围等标准 本地变量: 生效范围为当前shell进程:对当前shell之外的其他shell进程,包括当前shell的子shell进程均无效 环 ...
- js弹出对话框的三种方式(转)
原文地址:https://www.jb51.net/article/81376.htm javascript的三种对话框是通过调用window对象的三个方法alert(),confirm()和prom ...
- ajax全选、全不选、反选、单删/批删
<meta charset="utf-8"> <?php //链接数据库 $link = mysqli_connect('127.0.0.1','root','r ...
- Android查看appPackage和Activity的多种方法
方法一 有源码的情况直接打开AndroidManifest.xml文件,文件会有package信息 android.intent.action.MAIN决定应用程序最先启动的Activity andr ...
- C# 关键字base用法
1.调用基类的方法 public class A { public virtual void Hello() { Console.WiriteLine("Hello"); } } ...