?? file.h
字號:
#ifndef FILE_H
#define FILE_H
#include<fstream.h>
template<class T>
struct Element { T n;
Element *next;
};
template<class T>
class File
{
public:
File()
{}
File(char *n,int m=0)
{ FileName=new char[strlen(n)+1];
strcpy(FileName,n);
T t;
ifstream fin;
fin.open(FileName);
Element<T> * point=0,*p=0;
Head=new Element<T>;
Head->next=0;
p=Head;
while(fin.eof())
{
point=new Element<T>;
point->next=0;
m++;
fin>>t;
point->n=t;
p->next=point;
Tail=point;
p=point;}
Num+=m;
fin.close();
}
//friend class control;/////kenengshizhegedaozhilianjiewenti
void writein()
{
T t;int i=0;
ofstream fout;
fout.open(FileName,ios::app);
while(cin>>t)
{fout<<t<<endl;
i++;}
Num+=i;
}
void deal(char *name)//刪除紀錄
{
int flag=0;
Element<T> *p1=0,*p2=0,*p3=0;
p1=Head;
p2=Head->next;
p3=p2->next;
while(p2!=0)
{if(p2->n.name==name)///////////////////////////////////////////如何解決
if(p1==Head)
{
Head=p3;
flag=1;
return ;
}
else{
p1->next=p3;
flag=1;
return ;
}
p1=p2;
p2=p3;
p3=p3->next;
}
if(flag==0)
cout<<"沒有您要刪除的職員"<<endl;
}
bool Find( T&t)//添加時考慮是已經存在
{ Element<T> *p=0;
p=Head->next;
while(p!=0)
{if(p->n==t)
return true;
p=p->next
}
return false;
}
void sercherName(char *name)
{ Element<T> *p;
p=Head->next;
while(p!=0)
{if(p->n.name==name)/////////////////////////////////////////////////////////////如何解決
{cout<<p->n;
return ;}
p=p->next;
}
cout<<"對不起,沒有您查找的人請確認您輸入的名字是否正確"<<endl;
}
void sercherID(char *id)
{ Element<T> *p;
p=Head->next;
while(p!=0)
{if(p->n.ID==id)
{cout<<p->n;
return ;}
p=p->next;
}
cout<<"對不起,沒有您查找的人請確認您輸入的ID號是否正確"<<endl;
}
void add(T t)
{ Element<T> *p=0;
p=new Element<T>;
p->n=t;
Tail->next=p;
Tail=p;
}
void replace(T t)
{
Element<T> *p=0;
p=Head->next;
while(!p=0)
{if(t==p->n)
{ p->n=t;
return;}
p=p->next;
}
}
protected:
int Num;
char *FileName;
Element<T> *Head;//////原先沒有注意到
Element<T> *Tail;/////原先沒有注意到
};
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -