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 ...
随机推荐
- nmon监控数据分析
性能测试中,各个服务器资源占用统计分析是一个很重要的组成部分,通常我们使用nmon这个工具来进行监控以及监控结果输出. 一. 在监控阶段使用类似下面的命令 ./nmon -f write_3s_20v ...
- Windows下Python安装numpy+mkl,Scipy和statsmodels
最近做时间序列分析需要用到Python中的statsmodels,但是安装过程中遇到很头疼的问题,Google.Stackover各种都没有找到合适的解决办法,而且貌似还有很多同学也在吐槽Window ...
- 【Git】git error记录之 "unpacking the sent packfile failed on the remote"
错误信息: error: cannot open .git/FETCH_HEAD: Permission denied unpacking the sent packfile failed on th ...
- Linux——入门命令
授课内容: 0.linux系统由来 linux各种常用命令以及对命令参数选项的熟悉: 1.目录操作命令([跳转:查看自己当下的位置-绝对路径:查看任何路径下的目录内容]pwd(Print Workin ...
- 1.6 安全认证与授权(springboot与安全)
引言:以下文档是学习尚硅谷关于springboot教学视频后整理而来! 一.安全 认证(Authentication):证明你是谁? 授权(Authorization):你能干什么? 参考资料: Sp ...
- 网络3-Jsonp
解决跨域问题的几种办法 1.Flash (不做讨论) 2.服务器代理中转 3.Jsonp 4.document.domain(针对基础域名相同的情况)bj.58.com document.domain ...
- Codeforces 1100 F - Ivan and Burgers
F - Ivan and Burgers 思路:线性基+贪心,保存线性基中每一位的最后一个 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #p ...
- html5的websocket
转载:http://blog.csdn.net/liuhe688/article/details/50496780 var WebSocketServer = require('ws').Server ...
- [JavaScript-Function] Function Invocation/Call(函数调用) 以及call() and apply() 方法
介绍:JS函数中的代码会被函数被invoke(调用)时执行. 函数被定义时代码不执行, 函数调用时函数内的代码会被执行. 常用的term是 call a function 而不是 invoke a f ...
- double 类型转化为Integer
(1)把double先转化成int类型 Double reseve3=Double.parseDouble(bddet[0].getReserve3()); int b=reseve3.intValu ...