[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次,包括他 ...
随机推荐
- SQL分析“聚集索引、非聚集索引”区别
概述 聚集索引 一种索引,该索引中键值的逻辑顺序决定了表中相应行的物理顺序. 聚集索引确定表中数据的物理顺序.聚集索引类似于电话簿,后者按姓氏排列数据.由于聚集索引规定数据在表中的物理存储顺序,因此一 ...
- java面试一日一题:在创建微服务时,是用RPC还是http
问题:请讲下在做微服务时,是使用RPC还是http 分析:该问题主要考察对RCP及http的理解,也关系到在进行微服务选型时的两大方向,dubbo和springCloud,都是RPC框架,但前者是RP ...
- win10远程桌面连接报错:出现身份验证错误,要求的函数不受支持(CredSSP)
问题 解决办法 找到路径:计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System 在Syste ...
- 一些常用的Utils总结
1.BeanUtils.copyProperties,来自spring框架,作用是把对象的属性拷贝给另一个对象 BeanUtils.copyProperties(employeeDTO,employe ...
- 2024-07-31:用go语言,给定两个正整数数组arr1和arr2,我们要找到属于arr1的整数x和属于arr2的整数y组成的所有数对(x, y)中,具有最长公共前缀的长度。 公共前缀是指两个数的
2024-07-31:用go语言,给定两个正整数数组arr1和arr2,我们要找到属于arr1的整数x和属于arr2的整数y组成的所有数对(x, y)中,具有最长公共前缀的长度. 公共前缀是指两个数的 ...
- P5665 [CSP-S2019] 划分
思路: 首先求出 \(a\) 的前缀和数组 \(s\). 考虑动态规划,令 \(dp_{i,j}\) 表示以 \(i\) 结尾,末尾有 \(j\) 个为一组的最小答案,则状态转移方程为: \[dp_{ ...
- 全球首颗车规5纳米 高性能智驾芯片蔚来神玑NX9031 流片成功
地址: https://weibo.com/tv/show/1034:5060774108790867 https://www.bilibili.com/video/BV1JG411r7LR/
- gpg 密钥的导入、导出
参考: gpg 密钥生成.导入.导出.自动输入密码 How do I delete secret subkeys correctly? 注意: 本文不对GPG的操作做详细介绍,有深入了解者自行参考:g ...
- ubuntu18.04 环境下如何为 vscode 安装kite
传说中的Python环境下最好用的智能补全工具 kite =============================================================== 1. ...
- 【转载】 Do's and Don'ts of using t-SNE to Understand Vision Models —— t-SNE 作者写的使用指南(PPT版本)
<Do's and Don'ts of using t-SNE to Understand Vision Models> 作者的PPT视频:https://www.youtube.com/ ...