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. Python 华为云OSS建桶与文件上传下载删除及检索示例

    华为云OSS建桶与文件上传下载删除及检索示例 实践环境 运行环境: Python 3.5.4 CentOS Linux release 7.4.1708 (Core)/Win10 需要安装以下类库: ...

  2. mybatis关于大于小于:元素内容必须由格式正确的字符数据或标记组成。

    首先是原因: mybatis中< >这两个符号会被识别为标签的开始和结束,用了就会报解析的错误 会报错类似下面这些 1.元素内容必须由格式正确的字符数据或标记组成. 2.Error cre ...

  3. 【Java】Spring5学习

    基础环境与文档资料: 见黑马视频: https://www.bilibili.com/video/BV1P44y1N7QG 依赖坐标: <?xml version="1.0" ...

  4. 【H5】07 网页调试

    摘自: https://developer.mozilla.org/zh-CN/docs/Learn/HTML/Introduction_to_HTML/Debugging_HTML HTML 优雅明 ...

  5. python3.6—opencv-python报错:Exception: Not found: 'python/cv2/py.typed'

    报错: self).run_setup(setup_script=setup_script) File "/tmp/pip-build-env-zsqslesq/overlay/lib/py ...

  6. 在国产超算平台上(aarch64架构)安装pytorch-cuda失败,究其原因竟是官方未提供对应的cuda版本——pip方式和conda方式均无法获得相应cuda版本

    最近在国产超算平台上安装pytorch,但是怎么弄都会报错: raise AssertionError("Torch not compiled with CUDA enabled" ...

  7. H5页面\PC端实现QQ客服功能

    1.背景 很多应用都有在线客服,最简单是实现就是利用人们常用的QQ 2.实现 步骤一:授权QQ通讯组件(普通QQ都是可以的) 授权链接:https://shang.qq.com/v3/widget.h ...

  8. 免费领取云主机,在华为开发者空间玩转YOLOV3

    摘要:YOLOv3(You Only Look Once version 3)是一种高效的目标检测算法,旨在实现快速而准确的对象检测. 本文分享自华为云社区<华为云开发者云主机体验[玩转华为云] ...

  9. centos7系统 通过编译安装gcc7.5.0

    背景: 现有的centos7 gcc的最高版本为4.8.5 项目需要升级到7.1.0以上 正常方式可以通过以下命令即可完成升级: $ sudo yum install centos-release-s ...

  10. 通过 C# 将数据写入到Excel表格

    Excel 是一款广泛应用于数据处理.分析和报告制作的电子表格软件.在商业.学术和日常生活中,Excel 的使用极为普遍.本文将详细介绍如何使用免费.NET库将数据写入到 Excel 中,包括文本.数 ...