当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
navicat for Oraclel链接oracle 报错oracle library is not loaded的解决办法
What is the difference between the four common resistors?
What is a template engine?What are the common template engines?Introduction to common commands of thymeleaf.
[MySql]实现多表查询-一对一,一对多
常见的四种电阻之间有什么不同?
Regular Expressions for Shell Programming
【超级账本开发者系列】专访——肖慧 : 不忘初心,方得始终
focal loss原理及简单代码实现
Redis6.2.1配置文件详解
DBCO-PEG-DSPE, Phospholipid-Polyethylene Glycol-Dibenzocyclooctyne, Reaction Without Copper Ion Catalysis
随机推荐
如何灵活运用量化交易接口的优势取长补短?
股票程序化交易如何理解自己的交易系统?
分析:通过哪种方法来建立股票量化交易数据库?
正则化原理的简单分析(L1/L2正则化)
How to make your quantitative trading system have probabilistic advantages and positive return expectations?
如何通过通达信量化交易接口达到长期的收益?
常用类学习
Technology Sharing | How to Handle Header Cookies in Interface Automation Testing
Mind map FreeMind installation problems and simple use
Mongodb增加权限管理
How do quantitative investors obtain real-time market data?
量化程序化交易都有哪些热点争议?
redis从入门到精通
几何光学简介
Regular Expressions for Shell Programming
经典面试题 之 JVM调优
ImageWatch无法显示图像
Startup error: Caused by: org.apache.ibatis.binding.BindingException summary solution
PAT1027 打印沙漏
【C语言初阶】求最小公倍数的三种方法