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. JDBC第二天:防sql攻击

    1 什么是SQL攻击 在需要用户输入的地方,用户输入的是SQL语句的片段,最终用户输入的SQL片段与我们DAO中写的SQL语句合成一个完整的SQL语句!例如用户在登录时输入的用户名和密码都是为SQL语 ...

  2. 【Axure RP】Axure RP 9 下载安装及汉化

    本体及破解机下载: http://www.sd173.com/soft/7951.html 汉化补丁教程见: https://blog.csdn.net/weixin_74457789/article ...

  3. 【Spring-Security】Re13 Oauth2协议P3 整合JWT

    视频地址: https://www.bilibili.com/video/BV12D4y1U7D8?p=44 有用到Redis存储JWT,头疼每次找Windows版的 https://github.c ...

  4. idea中多线程debug实现方案

    1.背景 2.步骤 步骤一: 步骤二: 步骤三: 启动测试,查看个线程状态 完美

  5. SpringWebflux详细讲解

    1.背景 2.Spring5 框架新功能(Webflux) 2.1.SpringWebflux 介绍 (1)webFlux是 Spring5 添加的新模块,用于 web 的开发,功能和 SpringM ...

  6. [学习笔记] LCA - 图论

    [NOIP2013 提高组] 货车运输 最大生成树+LCA+倍增 好家伙,这道题我写了一个晚上,调了两个晚上,对于这道题我颇有感触.但这道题确实好,实实在在的蓝题,让我发现了许多关于LCA的问题. 首 ...

  7. JDK、JRE和JVM简述

    JDK(Java Development Kit) JDK是Java开发环境的核心组件,包括:Java编译器.JRE(Java运行环境)JavaDoc文档生成器和其他一些工具. JDK是Java程序员 ...

  8. 18-canvas绘制饼状图

    1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="U ...

  9. 09-canvas绘制坐标系

    1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="U ...

  10. **错误积累&&防止GG写法总结

    19.3.20 关于int与ll 1.如果一道题时间充足,把全部变量定义成long long 2.特别注意最上面宏定义的变量类型,特别是FOR 3.如果是int,用1LL* ...... **实例,让 ...