[namespace hdk] diff.h
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的更多相关文章
- c++,命名空间(namespace)
1.什么是命名空间: 命名空间:实际上就是一个由程序设计者命名的内存区域,程序设计者可以根据需要指定一些有名字的空间域,把一些全局实体分别放在各个命名空间中,从而与其他全局实体分隔开来. 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 ...
- codeforces gym101243 A C D E F G H J
gym101243 A #include<iostream> #include<cstdio> #include<cmath> #include<cstrin ...
- 【分段哈希】H. Paint the Wall
https://www.bnuoj.com/v3/contest_show.php?cid=9147#problem/H [题意] 在一个长为H,宽为W的白墙上选一个矩形区域涂颜色,后涂的颜色会覆盖先 ...
- kubernetes强制删除namespace
1.执行命令删除namespace后一直显示Terminating,无法删除namespace [root@k8s-master1 ~]# kubectl get ns NAME STATUS AGE ...
- 理解Docker(1):Docker 安装和基础用法
本系列文章将介绍Docker的有关知识: (1)Docker 安装及基本用法 (2)Docker 镜像 (3)Docker 容器的隔离性 - 使用 Linux namespace 隔离容器的运行环境 ...
- 转)ZooKeeper的实现分析
最近在大量看关于Zookeeper的博客,发现一篇讲解ZK实现很详细的博客,特此转载一下: 原博客地址: http://my.oschina.net/zhengyang841117/blog/1866 ...
- Docker 安装和基础用法
理解Docker(1):Docker 安装和基础用法 本系列文章将介绍Docker的有关知识: (1)Docker 安装及基本用法 (2)Docker 镜像 (3)Docker 容器的隔离性 - 使用 ...
- [SinGuLaRiTy] 高级搜索算法
[SinGuLaRiTy-1039] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 迭代加深搜索(ID) 迭代加深搜索,实质上就是限定下界的 ...
- Codeforces704C. Black Widow
n<=1e5个值v,分别由<=1e5的m个变量中的1<=ki<=2个布尔变量xj(或某个变量取反)或起来组成,而所有的v异或起来为1,一个x不会在输入数据中出现超过2次,包括他 ...
随机推荐
- wails实现腾讯元器bot
简单记录工具的一个模块 后端 Api调用 登录 腾讯元器 后创建智能体,按自己的需求来创建,发布后要等等审核. 等发布完成后点击调用api即可,这里可以看到user_id, assistant ...
- css 蛇形排序
先看效果 需求: 一个[ 4 * ?]的网格布局,奇数行 布局 从左往右,偶数行 布局 从右往左. 思路1: js将数组按4个每份进行分割,将偶数份进行反向,然后再将分割后的数据,重新组装.( 太麻 ...
- 使用ventoy安装windows10
使用ventoy安装windows10 在ventoy中选择windows10镜像 进入Windows安装界面 下一步,选择现在安装 稍等片刻 选择我没有产品密钥 根据需求选择对应版本 下一步,接受许 ...
- 安卓开发(java.lang.NullPointerException: Attempt to invoke virtual method ‘void android.view.View...)空指针异常
无论是初学者还是做开发很久的人都会遇到这个问题,那就是空指针异常: 遇到这种情况我们首先不要惊慌,一般这个问题都不是很大的问题,只需要我们 静下心来慢慢的查找,下面分成几步来带你查找问题: 1:首先是 ...
- 认识netty的基本组件
Java NIO VS Netty 有了 Java NIO,而且 Netty 也是基于 Java NIO 实现,那么为什么不能直接用 Java NIO 来实现网络通信模块呢? 接下来我就给大家解释一下 ...
- iOS开发基础144-逐字打印效果
在AIGC类的APP中,实现那种一个字一个字.一行一行地打印出文字的效果,可以通过多种方法来实现.下面是一些实现方法,使用Swift和OC来举例说明. OC版 1. 基于定时器的逐字打印效果 可以使用 ...
- 【MongoDB】Re05 分片集群(Win平台搭建)
分片副本集1 (3实例) 主1 从1 裁1 分片副本集2 (3实例) 主1 从1 裁1 配置副本集(3实例) 主1 从2 路由(2配置) 用Windows平台搭建 配置目录设置: ├─config ...
- 使用 abortNavigation 阻止导航
title: 使用 abortNavigation 阻止导航 date: 2024/8/3 updated: 2024/8/3 author: cmdragon excerpt: 摘要:在Nuxt3中 ...
- 搞IT的为什么不建议搞底层(操作系统、编译器、编程语言)——当你搬进你的新家之后,你会在意这个楼是谁打的地基吗?—— 要站在钱流动的地方
文字表达引自:https://www.youtube.com/watch?v=KITqGv1qYg8 当你搬进你的新家之后,你会在意这个楼是谁打的地基吗?你猜猜那些打地基的工人赚多少钱,卖你沙发电视机 ...
- 强化学习是否可以AI4Science呢?
最近,华为和Google都推出了AI的天气预报系统(发表了nature.science论文,但是没开放公众使用),可以说这个传统的Science问题已经被AI算法解决,这也说明了传统Science问题 ...