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 ...
随机推荐
- Linux上不了网的几个排查点
下面是所有系统通用排查流程: 1.先ping网关: 例ping 192.168.12.1: 如果能通说明本地IP配置和本地到路由器的链路未发生问题. 如果不通需要检查本地设置和本地到路由的网线连接状态 ...
- HTTP1.0、HTTP1.1 和 HTTP2.0 的区别
一.HTTP的历史 早在 HTTP 建立之初,主要就是为了将超文本标记语言(HTML)文档从Web服务器传送到客户端的浏览器.也是说对于前端来说,我们所写的HTML页面将要放在我们的 web 服务器上 ...
- 剑指offer(60)把二叉树打印成多行
题目描述 从上到下按层打印二叉树,同一层结点从左至右输出.每一层输出一行. 题目分析 从上到下打印二叉树我们知道用队列可以实现,但是如果多行打印怎么做呢? 我们需要分割,在行与行之间进行分割.如何分割 ...
- Qt Windows打开指定文件注意替换双斜杠为单斜杠
QProcess::startDetached(QString("explorer %1").arg(strFilePath)); 其中,在windows上使用时,strFileP ...
- css 两端对其
大段的文字直接写会有不整齐的现象 所以ui小姐姐就会和我们讲你能不能把两端对其呀 ps里面就可以呀 okok 那就两端对其好了 text-align:justify 效果为⬇️⬇️⬇️ 上面是 ...
- Jupyter Notebook插入图片的4种方法
来自:https://blog.csdn.net/qq_33039859/article/details/78507316 方法1:  Markdown ...
- 简单的class及运算符重载
#include <iostream> #include <vector> #include <algorithm> using namespace std; cl ...
- .NET Core / C# 开发 IOT 嵌入式设备的个人见解
https://www.cnblogs.com/whuanle/p/10589496.html
- 不正常退出vim产生swp文件的解决方法
vi -r README.txt恢复文件,这样上次意外退出没有保存的修改,就会覆盖文件. vi -r查看生成的交换文件 rm .README.txt.swp删除交换文件 搞定!下次打开文件就可以正常编 ...
- spring cloud(二)服务(注册)中心Eureka
Eureka是Netflix开源的一款提供服务注册和发现的产品,它提供了完整的Service Registry和Service Discovery实现.也是springcloud体系中最重要最核心的组 ...