65,189
社区成员




//main.cpp
#include<string>
#include<stdlib.h>
#include<iostream.h>
#include<fstream.h>
#include<iomanip.h>
#include"file.h"
void main()
{ char *p1=".\\File.dat",*p2=".\\File.idx";
File<IndexItem,ElemType>myfile;
ElemType e; //记录元素
while(1){
cout<<"欢迎\n";
cout<<"1-增加记录\t 2-删除记录\t 3-查找记录\n 4-浏览记录\n ";
char choice;
cin>>choice;
switch(choice)
{case '1':
myfile.inputElem(e);
cout<<e.key<<endl<<e.length ;
myfile.Append(p1,p2,e);break;
}
}//end while
}
//file.h
#include<stdlib.h>
#include<stdio.h>
#include<fstream.h>
#include<iostream.h>
#include<string>
using namespace std;
typedef char KeyType;
//主文件的记录类型
struct ElemType{
KeyType key[10]; //关键字域
string content; //内容域
int length; //内容长度
};
//索引文件的记录类型
struct IndexItem{
KeyType key; //关键字域
int next; //对应记录位置
};
template<class T,class T1> //T==IndexItem;T1==ElemType
class File
{public:
ElemType inputElem(ElemType & e);
void Append(char*fn1,char*fn2,T1 );
};
//Elem.cpp
#include"file.h"
template<class T,class T1> //T==IndexItem;T1==ElemType
ElemType inputElem(T1 & e)
{
......
}
#include <stdlib.h>
#include <iomanip.h>
#include <string>
using namespace std;
#include"file.h"
#include <stdlib.h>
#include <iomanip.h>
#include <string>
#include"file.h"
using namespace std;
#define keylenth 10
typedef char KeyType[keylenth];
//主文件的记录类型
struct ElemType{
KeyType key; //关键字域
string content; //内容域
int length; //内容长度
};
//记录关键字类型
typedef char KeyType;
//主文件的记录类型
struct ElemType{
KeyType key[10]; //关键字域
string content; //内容域
int length; //内容长度
};