首页 > 数字化转型 > ERP > 一个简单的文件管理程序 (转)
node.h
====================================
#include
template
class node
{
private:
node
public:
T data;
node(void);
node(T data1,node
void insertafter(node
void deleteafter(void);
node
};
template
node
{
next=NULL;
}
template
node
{
data=data1;
next=p;
}
template
void node
{
p->next=next;
next=p;
}
template
void node
{
node
temp=next;
next=temp->next;
delete temp;
}
template
node
{
return next;
}
list.h
=====================================
#include
#include
#include"node.h"
template
class list
{
private:
node
public:
list(void);
node
void createlist(T data2,node
void Insertlast(T p);
void deletedata(T d);
void print(void);
void deletelist(void);
void athead(void);
T Data(void);
node
node
};
template
list
{
head=NULL;
newnode=NULL;
last=NULL;
currnode=NULL;
prenode=NULL;
}
template
node
{
newnode=new node
return newnode;
}
template
void list
{
newnode=new node
if(head==NULL)
{
head=newnode;
}
else
{
currnode=head;
while(currnode->nextnode()!=NULL)
{
currnode=currnode->nextnode();
}
currnode->insertafter(newnode);
currnode=newnode;
}
last=newnode;
}
template
void list
{
newnode=new node
if(last->nextnode()==NULL)
{
last->insertafter(newnode);
}
else
{
cout<<"there are some error in last"<
}
}
template
void list
{
if(head==NULL)
{
cout<<"no data in the list"<
}
if(head->data==d)
{
head=head->nextnode();
}
else
{
currnode=head;
while(currnode!=NULL)
{
if(currnode->data!=d)
{
prenode=currnode;
currnode=currnode->nextnode();
}
else
{
prenode->deleteafter();
currnode=prenode->nextnode();
}
}
}
}
template
void list
{
currnode=head;
if(head==NULL)
{
cout<<"no data in list"<
}
while(currnode!=NULL)
{
cout<
currnode=currnode->nextnode();
}
cout<
template
void list
{
node
if(head==NULL)
{
cout<<"no data in list"<
}
while(head!=NULL)
{
temp=head;
head=head->nextnode();
delete temp;
}
}
template
void list
{
if(head!=NULL)
{
currnode=head;
}
else
{
cout<<"no data at head"<
}
}
template
T list
{
if(currnode!=NULL)
{
return currnode->data;
}
}
template
node
{
if(currnode!=NULL)
{
currnode=currnode->nextnode();
return currnode;
}
else
{
return NULL;
}
}
template
node
{
return currnode;
}
guanli.cpp
============================================
#include
#include
#include
#include"list.h"
struct file // file struct;
{
string filename;
string aboutfile;
string filepath;
};
struct getfile
{
string filename;
string aboutfile;
string filepath;
};
void main(void)
{
int select;
file myfile;
string space,findvalue;
ofstream writefile;
list
char ch,text;
int stringsize,i;
for(;;)
{
string linevalue; // jing zhi zai for(;;){} xuan huan zhong ding yi(1-3);
string openname("/home/c++/zuoping2/jiru");// 2
ifstream readfile(openname.c_str(),ios::in);//3
string::size_type pos=0,pre=0;
getfile getmyfile;
cout<<"1:add file"<
switch(select)
{
case 1:
writefile.open("/home/c++/zuoping2/jiru",ios::out | ios::app);
if(!writefile)
{
cout<<"Don't open jiru file"<
}
getline(cin,space,'n');
cout<<"please input file name"<
cout<<"please input file description"<
cout<<"please input file path"<
if(myfile.filepath[myfile.filepath.size()-1]=='/')
{
writefile<
else
{
myfile.filepath=myfile.filepath+"/";
writefile<
writefile.close();
break;
case 2:
if(!readfile)
{
cout<<"Don't open jiru file"<
}
cout<<"please input file name for finding file"<
while(getline(readfile,linevalue,'n'))
{
pre=0;
pos=0;
//get file name;
pos=linevalue.find_first_of(';',pos);
getmyfile.filename=linevalue.substr(pre,pos-pre); ++pos;
pre=pos;
//get file description;
pos=linevalue.find_first_of(';',pos);
getmyfile.aboutfile=linevalue.substr(pre,pos-pre);
++pos;
pre=pos;
//get file path;
pos=linevalue.find_first_of(';',pos);
getmyfile.filepath=linevalue.substr(pre,pos-pre);
++pos;
pre=pos;
//get getmylist data for create list;
mylist.createlist(getmyfile);
}
mylist.athead();
while(mylist.Currnode()!=NULL)
{
if(mylist.Data().filename==findvalue) //when find file;
{
cout<<"find file"<
if(ch=='y')
{
string filepath;
filepath=mylist.Data().filepath+mylist.Data().filename;
//erase char 'n';
for(i=0;i<=filepath.size();i++)
{
if(filepath[i]=='n')
{
filepath.erase(i,1);
}
}
//open file;
ifstream openfiles;
openfiles.open(filepath.c_str(),ios::in);
if(!openfiles)
{
cerr<<"don't open file"<
}
//read file context;
while(!openfiles.eof())
{
openfiles.get(text);
cout.put(text);
}
}
}
mylist.Next();
}
mylist.deletelist();
break;
case 3:
if(!readfile)
{
cerr<<"don't open the file"<
}
while(getline(readfile,linevalue,'n'))
{
//get file name;
pos=linevalue.find_first_of(';',pos);
getmyfile.filename=linevalue.substr(pre,pos-pre); ++pos;
pre=pos;
//get file description;
pos=linevalue.find_first_of(';',pos);
getmyfile.aboutfile=linevalue.substr(pre,pos-pre);
++pos;
pre=pos;
//get file path;
pos=linevalue.find_first_of(';',pos);
getmyfile.filepath=linevalue.substr(pre,pos-pre);
++pos;
pre=pos;
//get getmylist data for create list;
mylist.createlist(getmyfile);
pos=0;
pre=0;
}
mylist.athead();
while(mylist.Currnode()!=NULL)
{
string filepath,descp;
cout<<"the file description"<
if(ch=='y')
{
filepath=mylist.Data().filepath+mylist.Data().filename;
pos=0;
for(i=0;i<=filepath.size();i++)
{
if(filepath[i]=='n')
{
filepath.erase(i,1);
}
}
cout<
openfiles.open(filepath.c_str(),ios::in);
if(!openfiles)
{
cerr<<"don't open file"<
}
while(!openfiles.eof())
{
openfiles.get(text);
cout.put(text);
}
}
else if(ch=='q')
{
break;
}
mylist.Next();
}
mylist.deletelist();
break;
case 5:
exit(0);
}
}
}
makefile
========================================================
guanli:guanli.o list.h node.h
g++ -g -I/home/c++/zuoping2/ guanli.cpp -o guanli
all:guanli
.PHONY:clean
clean:
RM guanli.o
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10752019/viewspace-985508/ ,如需转载,请注明出处,否则将追究法律责任。