C++->10.3.6.设有两个按升序排列的二进制文件a和b,将他们合并成一个新的升序二进制数据文件file。
#include<iostream.h>
#include<stdlib.h>
#include<string.h>
#include<fstream.h>
struct staff{
long staNum;
char staName[500];
long phoNum;
long num;
char staAddr[1000];
}staf,staf1;
void main(){
fstream fstr1,fstr2,fstr,fstrt;
char i,fn1[80],fn2[80],fn[80],fnt[80],*p1,*p2,*p,*pt,str[1000];
//staff staf1;
int a,b;
p1=&fn1[0]; p2=&fn2[0]; p=&fn[0]; pt=&fnt[0];
cout<<"Please input the file name of fn1:\n";
//cin>>p1;
//fstr1.open(p1,ios::binary|ios::in|ios::out); //1
fstr1.open("E:\\新建文件夹\\新建文件夹\\a.bat",ios::binary|ios::in|ios::out);
if(!p1){ cerr<<"Can't open the file fn1.\n"; return; }
fstr1.seekp(0,ios::end);
cout<<"Please input the number i(Y|y).\n";
cin>>i;
while(i=='Y'||i=='y'){
cout<<"Please input the number staf.\n";
cin>>staf.staNum>>staf.staName>>staf.phoNum>>staf.num>>staf.staAddr;
fstr1.write((char *) &staf,sizeof(staf)); //文件名对象.write函数里的buffer类型只能是(char *),不能是其他类型fstr1.write((int *) &a,sizeof(a));
cout<<"Please input the number i.(Y|y)\n";
cin>>i; }
cout<<"Please input the file name of fn2:\n";
//cin>>p2;
//fstr2.open(p2,ios::binary|ios::in|ios::out); //2
fstr2.open("E:\\新建文件夹\\新建文件夹\\b.bat",ios::binary|ios::in|ios::out);
if(!p2){ cerr<<"Can't open the file fn2.\n"; return; }
fstr2.seekp(0,ios::end);
cout<<"Please input the number i.(Y|y)\n";
cin>>i;
while(i=='Y'||i=='y'){
cout<<"Please input the number staf1.\n";
cin>>staf1.staNum>>staf1.staName>>staf1.phoNum>>staf1.num>>staf1.staAddr;
fstr2.write((char *) &staf1,sizeof(staf1));
cout<<"Please input the number i(Y|y).\n"; cin>>i; }
cout<<"Please input the file name of fn.\n"; //3
//cin>>p;
//fstr.open(p,ios::binary|ios::in|ios::out);
fstr.open("E:\\新建文件夹\\新建文件夹\\file.bat",ios::binary|ios::in|ios::out);
if(!p){ cerr<<"Can't open the file of fn.\n"; return; }
fstr1.seekp(0,ios::end);
long pEnd1=fstr1.tellp();
fstr2.seekp(0,ios::end);
long pEnd2=fstr2.tellp();
fstr1.seekp(0,ios::beg);
fstr2.seekp(0,ios::beg);
while(fstr1.tellp()!=pEnd1&&fstr2.tellp()!=pEnd2){
fstr1.read((char *) &staf,sizeof(staf));
fstr2.read((char *) &staf1,sizeof(staf1));
if(staf.staNum>>staf1.staNum) fstr.write((char *) &staf,sizeof(staf));
else fstr.write((char *) &staf1,sizeof(staf1));
//fstr<<staf1.staNum<<ends<<staf1.staName<<ends<<staf1.phoNum<<ends<<staf1.num<<staf1.staAddr; }
while(fstr1.tellp()!=pEnd1) fstr.write((char *) &staf,sizeof(staf));
while(fstr2.tellp()!=pEnd2) fstr.write((char *) &staf1,sizeof(staf1));
cout<<"Please input the file name of fn4.\n"; //4
//cin>>pt;
//fstrt.open(pt,ios::in|ios::out);
fstrt.open("E:\\新建文件夹\\新建文件夹\\l.txt",ios::in|ios::out);
if(!pt){ cerr<<"Can't open the file of fn.\n"; return; }
fstr.seekg(0,ios::end);
long pEnd3=fstr.tellg();
fstr.seekg(0,ios::beg);
while(fstr.tellg()!=pEnd3){
fstr.read((char *) &staf,sizeof(staf));
fstrt<<staf.staNum<<ends<<staf.staName<<ends<<staf.phoNum<<ends<<staf.num<<staf.staAddr<<endl;
cout<<staf.staNum<<ends<<staf.staName<<ends<<staf.phoNum<<ends<<staf.num<<staf.staAddr<<endl;
} cout<<endl; fstrt.close();
cout<<"Please input the file name of fn4.\n"; //5
//cin>>pt;
//fstrt.open(pt,ios::in|ios::out);
fstrt.open("E:\\新建文件夹\\新建文件夹\\l.txt",ios::in|ios::out);
if(!pt){ cerr<<"Can't open the file of fn.\n"; return; }
//while(fstrt.tellg()!=ptEnd){ fstrt.getline(fn,800);
//cout<<staf.staNum<<ends<<staf.staName<<ends<<staf.phoNum<<ends<<staf.num<<staf.staAddr<<endl; } //二进制的判断方法
do{ fstrt.getline(str,1000); cout<<str<<endl; }while(!fstrt.eof());
fstr1.close(); fstr2.close(); fstr.close(); fstrt.close();
} */
C++->10.3.6.设有两个按升序排列的二进制文件a和b,将他们合并成一个新的升序二进制数据文件file。的更多相关文章
- 将两个列不同的DataTable合并成一个新的DataTable
/// <summary> /// 将两个列不同(结构不同)的DataTable合并成一个新的DataTable /// </summary> ...
- 将两个数组相同index的value合并成一个新的value组成一个新的数组
将两个数组相同index的value合并成一个新的value组成一个新的数组 前提: 这两个数组的长度相同 生成后的新数组长度也相同 返回值都是对象 把rows对象的key和value弄成两个数组, ...
- Java-Runoob-高级教程-实例-字符串:10. Java 实例 - 测试两个字符串区域是否相等-uncheck
ylbtech-Java-Runoob-高级教程-实例-字符串:10. Java 实例 - 测试两个字符串区域是否相等 1.返回顶部 1. Java 实例 - 测试两个字符串区域是否相等 Java ...
- python之最强王者(10)———文件(File)、输入输出的基本操作
1. Python 文件I/O 本章只讲述所有基本的的I/O函数,更多函数请参考Python标准文档. 2.打印到屏幕 最简单的输出方法是用print语句,你可以给它传递零个或多个用逗号隔开的表达式. ...
- ORA-01578: ORACLE 数据块损坏 (文件号 10, 块号 57896)ORA-01110: 数据文件 10: '/data/oradata/prod35.dbf'
https://community.oracle.com/thread/3540795 概述 ------------- 数据库坏块(corruption) 的类型可以按照坏块所属对象的不同,分为用户 ...
- delphi 创建DBASE和FOXPRO两类DBF数据文件的差异
delphi 创建DBASE和FOXPRO两类DBF数据文件的差异,主要有几点: 1.创建方法不同 DBASE的创建方法: Self.Table1.Close; Self.Table1.Active ...
- 如何定义让两个div横向排列
方法一: 一般情况,默认的div是写一个换一行,那么如何定义两个div横向排列而不换行呢? div默认的display属性是block.所以每一个div都是新的一行,现在把display换成inlin ...
- 有两个序列A和B,A=(a1,a2,...,ak),B=(b1,b2,...,bk),A和B都按升序排列。对于1<=i,j<=k,求k个最小的(ai+bj)。要求算法尽量高效。
有两个序列A和B,A=(a1,a2,...,ak),B=(b1,b2,...,bk),A和B都按升序排列.对于1<=i,j<=k,求k个最小的(ai+bj).要求算法尽量高效. int * ...
- python将两个数组合并成一个数组的两种方法的代码
内容过程中,把写内容过程中常用的内容收藏起来,下面的资料是关于python将两个数组合并成一个数组的两种方法的内容,希望能对小伙伴们有帮助. c1 = ["Red","G ...
随机推荐
- 用Go语言在Linux下调用新中新DKQ-A16D读卡器,读二代证数据
1.背景 前几天用Python在Linux下成功的获取了二代证数据,最近正在学Go语言,这两天想着用Go语言也实现一下试看看. 2.开搞C++ 这次就比较简单了,直接把CppDemo里面的SynRea ...
- ARTS Week 14
Jan 27, 2020 ~ Feb 2, 2020 Algorithm Problem 160.Intersection of Two Linked Lists(相交链表) 题目链接 题目描述:给定 ...
- 动手学习pytorch——(3)多层感知机
多层感知机(multi perceptron,MLP).对于普通的含隐藏层的感知机,由于其全连接层只是对数据做了仿射变换,而多个仿射变换的叠加仍然是一个仿射变换,即使添加更多的隐藏层,这种设计也只能与 ...
- 动手学习pytorch——(1)线性回归
最近参加了伯禹教育的动手学习深度学习项目,现在对第一章(线性回归)部分进行一个总结. 这里从线性回归模型之从零开始的实现和使用pytorch的简洁两个部分进行总结. 损失函数,选取平方函数来评估误差, ...
- P3387缩点(tarjan+拓扑排序+线性dp)
题目描述 给定一个 n个点 m 条边有向图,每个点有一个权值,求一条路径,使路径经过的点权值之和最大.你只需要求出这个权值和. 允许多次经过一条边或者一个点,但是,重复经过的点,权值只计算一次. 输入 ...
- 苹果系统iOS、macOS应用管理机制
iOS.macOS系统应用管理机制 苹果系统包括:iOS.macOS.watchOS.tvOS.应用软件的生命周期为:开发.上线.安装.使用.卸载.这篇文档将从应用生命周期的各个环节介绍苹果系统对应用 ...
- Andriod you must restart adb and eclipse
今天看着视频 学习着 andriod ,启动 的时候 竟然报错 我试了N种google来的方法,都失效,现在把我的解决方法告诉大家,希望能帮到大家. 首先,我先罗列下我搜到的方法,大家也可以尝试. 1 ...
- [Windows]远程管理服务WinRM远程管理Windows服务器 Invalid use of command line. Type "winrm -?" for help.
运行环境 Windows 2012 R2 1. Windows需要打开WinRM服务,Server系统默认打开,默认端口5985 # WinRM服务查看 PS C:\Users\Administrat ...
- MacBook通过SSH远程访问Parallel中的Ubuntu简明教程
作为一个前端,后端也需要了解,最终选择PHP入手学习,本来想选择Python,思前想后还是PHP作为Web开发比较合适,环境最终选择Ubuntu开发,由于是第一次,遇到不少坑,经过不懈的努力不断Goo ...
- 一起了解 .Net Foundation 项目 No.6
.Net 基金会中包含有很多优秀的项目,今天就和笔者一起了解一下其中的一些优秀作品吧. 中文介绍 中文介绍内容翻译自英文介绍,主要采用意译.如与原文存在出入,请以原文为准. .NET Micro Fr ...