当前位置:网站首页>bin document read and write
bin document read and write
2022-08-09 16:17:00 【Nicolas0311】
今天遇到问题.When testing the mod before,Saved test databin文档多了2个byte数据.
Solving urgent problems is of course the most familiar way.
So I prepared itTestWinControlThe project wrote the following code.
bin Files文件夹中有100个1~100编号的.bin文档.After rewriting
bin文件夹中生成100The last two have been removedbyte的.bin文档.
#include "stdafx.h"
#include <afx.h>
#include <iostream>
using namespace std;
CString GetExeDir()
{
CString ExePath, ExeDir;
TCHAR tempPath[MAX_PATH] = {
0};
GetModuleFileName(NULL,tempPath,MAX_PATH);
ExePath = tempPath;
//NOTICE: The resulting path has the last strip *\*
ExeDir = ExePath.Left( ExePath.ReverseFind(_T('\\'))+1) ;
return ExeDir;
}
void WriteBin(CString szPath, unsigned char* data, int size)
{
FILE* pFile;
if (_wfopen_s(&pFile, szPath.GetBuffer() , _T("wb+")) == 0)
{
fwrite(data, 1, size, pFile);
fclose(pFile);
szPath.Format(_T("%s write"),szPath);
cout << "write size: " << size << endl;
}
}
void ReadBin(CString szPath, unsigned char* data, int size)
{
FILE* pFile;
if (_wfopen_s(&pFile, szPath.GetBuffer() , _T("rb+")) == 0)
{
fread(data, 1, size, pFile);
fclose(pFile);
szPath.Format(_T("%s read"),szPath);
cout << "read size: " << size << endl;
}
}
int main()
{
const int size = 1406;
unsigned char data[size] = {
0};
memset(data, 0, size);
const int wsize = 1404;
unsigned char wdata[wsize] = {
0};
memset(wdata, 0, wsize);
CString exeDir = GetExeDir();
CString readPath;
CString writePath;
CreateDirectory(exeDir + _T("bin\\"), NULL);
CFileFind finder;
BOOL bw = finder.FindFile(exeDir + _T("bin Files\\*.bin"));
while(bw)
{
bw = finder.FindNextFile();
if (finder.IsDots()) continue;
if (finder.IsDirectory()) continue;
CString fileName = finder.GetFileName();
readPath = exeDir + _T("bin Files\\") + fileName;
writePath = exeDir + _T("bin\\") + fileName;
ReadBin(readPath, data, size);
memcpy(wdata, data, wsize);
WriteBin(writePath, wdata, wsize);
}
return 0;
}边栏推荐
- 文件操作的实例——下载并合并流式视频文件
- MySQL principle and optimization: Limit the query optimization
- How to flexibly use the advantages of the quantitative trading interface to complement each other?
- Bessel function
- 是什么推动了量化交易接口的发展?
- Database multi-table link query method
- 常微分方程的幂级数解法
- 怎么才可以知道量化程序化交易是否有效?
- Play in the cloud | The ever-changing gameplay of Tianyi cloud computer
- 在量化交易过程中,散户可以这样做
猜你喜欢

内存泄露检测工具VLD(Visual Leak Detector)使用说明

Shell -- -- -- -- -- - common gadgets, sort and uniq, tr, the cut

Startup error: Caused by: org.apache.ibatis.binding.BindingException summary solution

数据库多表链接查询的方式

编译器不同,模式不同,对结果的影响

Regular Expressions for Shell Programming

走得通,看得见!你的交通“好帮手”
![[MySql] implement multi-table query - one-to-one, one-to-many](/img/7e/8f1af4422a394969b28a553ead2c42.png)
[MySql] implement multi-table query - one-to-one, one-to-many

常微分方程的幂级数解法

多线程学习
随机推荐
注解与反射
JVM简学笔记
How do users correctly understand programmatic trading?
名词概念总结(不定期更新~~)
6大论坛,30+技术干货议题,2022首届阿里巴巴开源开放周来了!
Analysis: Which method is used to build a stock quantitative trading database?
EasyExcel的应用
注释,标识符,数据类型
MongoDB adds permission management
常见的数学物理方程
For programming trading, focusing on forecast or on countermeasures?
常用类学习
How to achieve stable profit through the stock quantitative trading interface?
浅析Servlet三大容器的常用方法及其作用域
怎么用VS+Qt创建新项目
Talking about Shallow Cloning and Deep Cloning of ArraryList
Two-dimensional array to realize the eight queens problem
英语议论文读写02 Engineering
二叉排序树的左旋与右旋
如何保证电脑硬盘格式化后数据不能被恢复?