Example

cth.txt

12345
54321
114514

hdk.txt

12345
54321
114514
#include"diff.h"
using namespace hdk::diff;
using namespace std;
int main(){
fc("cth.txt","hdk.txt",true,true);//此两个true参数位置默认为false,可直接省略
// true:显示比较结果
// true:显示详细比较信息
//返回值:相同=false 不同=true
}

Result

fc cth.txt and hdk.txt
Compare: '12345' '12345'
Compare: '54321' '54321'
Compare: '114514' '114514'
File is equal.

Program

/*
* diff.h
* diff.h is a local C++ header file that
* used to compare and find the difference
* of two file
*
* Author : HaneDaniko
* Create Time: 25/7/2024
*
* To use this header, you must import this
* file into you programme
**/
#ifndef HDK
#define HDK 0
#endif
#ifndef diff_h
#define diff_h 0
#endif
#include<string>
#include<cstring>
#include<cstdio>
#include<fstream>
#include<vector>
namespace hdk{
namespace diff{
std::string a,b;
bool fc(char file_A[],char file_B[],bool display=false,bool debug_mode=false){
if(display){printf("fc %s and %s\n",file_A,file_B);}
bool eofA=false,eofB=false;std::ifstream f1,f2;f1.open(file_A);f2.open(file_B);
while(1){
if(f1.eof()){eofA=true;}
else{f1>>a;}
if(f2.eof()){eofB=true;}
if(eofA and eofB){if(display) printf("File is equal.\n"); return false;}
else if(eofA or eofB){if(display) printf("Length is not equal.\n");return true;}
else{f2>>b;}
if(debug_mode){printf("Compare: '%s' '%s'\n",a.c_str(),b.c_str());}
if(a!=b){if(display){
printf("Find Difference: \n");
printf("%s: %s\n",file_A,a.c_str());
printf("%s: %s\n",file_B,b.c_str());}
return true;
}
}
}
bool fc(std::string file_A,std::string file_B,bool display=false,bool debug_mode=false){
char A[200001],B[200001];
strcpy(A,file_A.c_str());
strcpy(B,file_B.c_str());
return fc(A,B,display,debug_mode);
}
template<typename T>
std::vector<T>read(std::ifstream x){
std::vector<T>an;T re;
while(!x.eof()){x>>re;an.push_back(re);}
return an;
}
template<typename read_out,typename func_out>
bool fc(char file_A[],char file_B[],read_out(*read_t)(std::ifstream),func_out(*func)(read_out)){
std::ifstream f1,f2;f1.open(file_A);f2.open(file_B);
read_out A=read_t(f1);read_out B=read_t(f2);
func_out x=func(A);func_out y=func(B);
if(x==y) return false;else return true;
}
}
}
/*--NAMESPACE HDK::DIFF DIFF_H_--*/

[namespace hdk] diff.h的更多相关文章

  1. c++,命名空间(namespace)

    1.什么是命名空间: 命名空间:实际上就是一个由程序设计者命名的内存区域,程序设计者可以根据需要指定一些有名字的空间域,把一些全局实体分别放在各个命名空间中,从而与其他全局实体分隔开来. 2.命名空间 ...

  2. [bcc32 Error] typeinfo.h(154): E2367 Can't inherit RTTI class from non-RTTI base 'exception'

    [bcc32 Error] typeinfo.h(154): E2367 Can't inherit RTTI class from non-RTTI base 'exception'  Full p ...

  3. codeforces gym101243 A C D E F G H J

    gym101243 A #include<iostream> #include<cstdio> #include<cmath> #include<cstrin ...

  4. 【分段哈希】H. Paint the Wall

    https://www.bnuoj.com/v3/contest_show.php?cid=9147#problem/H [题意] 在一个长为H,宽为W的白墙上选一个矩形区域涂颜色,后涂的颜色会覆盖先 ...

  5. kubernetes强制删除namespace

    1.执行命令删除namespace后一直显示Terminating,无法删除namespace [root@k8s-master1 ~]# kubectl get ns NAME STATUS AGE ...

  6. 理解Docker(1):Docker 安装和基础用法

    本系列文章将介绍Docker的有关知识: (1)Docker 安装及基本用法 (2)Docker 镜像 (3)Docker 容器的隔离性 - 使用 Linux namespace 隔离容器的运行环境 ...

  7. 转)ZooKeeper的实现分析

    最近在大量看关于Zookeeper的博客,发现一篇讲解ZK实现很详细的博客,特此转载一下: 原博客地址: http://my.oschina.net/zhengyang841117/blog/1866 ...

  8. Docker 安装和基础用法

    理解Docker(1):Docker 安装和基础用法 本系列文章将介绍Docker的有关知识: (1)Docker 安装及基本用法 (2)Docker 镜像 (3)Docker 容器的隔离性 - 使用 ...

  9. [SinGuLaRiTy] 高级搜索算法

    [SinGuLaRiTy-1039] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 迭代加深搜索(ID) 迭代加深搜索,实质上就是限定下界的 ...

  10. Codeforces704C. Black Widow

    n<=1e5个值v,分别由<=1e5的m个变量中的1<=ki<=2个布尔变量xj(或某个变量取反)或起来组成,而所有的v异或起来为1,一个x不会在输入数据中出现超过2次,包括他 ...

随机推荐

  1. MFC的消息反射

    这边我用对话框来测试mfc的消息反射 当对话框初始化完成之后,点击按钮,首先相应CDialog::OnCommand其中wpARAM(低八位nId,高八位子控件句柄) 和LPARAM(句柄) OnCo ...

  2. 带你学习通过GitHub Actions如何快速构建和部署你自己的项目,打造一条属于自己的流水线

    本文主要讲解通过github的actions来对我们项目进行ci/cd 一.actions简介 GitHub Actions 是一种持续集成和持续交付 (CI/CD) 平台,可用于自动执行生成.测试和 ...

  3. [rCore学习笔记 018]实现特权级的切换

    写在前面 本随笔是非常菜的菜鸡写的.如有问题请及时提出. 可以联系:1160712160@qq.com GitHhub:https://github.com/WindDevil (目前啥也没有 本节内 ...

  4. uniapp生成的app怎么上架到iphone的app store

    首先这里需要强调的是,上架app store,必须用自己公司的账号的证书打包,不能使用别的公司的证书打包,因为假如使用别人的证书打包,打包出来的app,只能上传到别人的app store账号,你开发的 ...

  5. Java--普通方法重载

    [转载自本科老师上课课件] 调用一个重载过的方法时,Java编译程序是如何确定究竟应该调用哪一个方法?以下代码定义了三个重载方法: public void f(char ch){ System.out ...

  6. AtCoder Beginner Contest 312

    AtCoder Beginner Contest 312 A - Chord (atcoder.jp) #include <bits/stdc++.h> #define endl '\n' ...

  7. springboot解析自定义yml

    springboot解析自定义yml 在实际项目开发中我们经常需要用到一些自定义配置,并且希望单独配置,方便维护,现在介绍下方式: 方式一手动加载 对于一些不变动的配置,写死在项目中维护,如下 然后在 ...

  8. 使用分布式锁解决IM聊天数据重复插入的问题

    导航 业务背景 问题分析与定位 探索可行的解决方案 数据库层面处理--唯一索引 应用程序层面处理--分布式锁 分布式锁概述 分布式锁需要具备哪些特性? 分布式锁有哪些实现方式? 基于数据库的实现方式 ...

  9. Mac 使用远程 Ubuntu 机器进行时间备份

    设置 SMB 服务 首先在 Ubuntu 中配置 SMB 服务.可以参考 Ubuntu 设置 SMB 服务. 创建 APFS 磁盘映像 我们在 Ubuntu 上创建出的 SMB 共享文件夹可以用来存放 ...

  10. 【Python爬虫】之爬取页面内容、图片以及用selenium爬取

    下面不做过多文字描述: 首先.安装必要的库 # 安装BeautifulSoup pip install beautifulsoup4 # 安装requests pip install requests ...