
#ifndef _CFILE_H_
#define _CFILE_H_
#include<stdio.h>
#include<string.h>
//using namespace std;
class CFile
{
private:
char *buf;
FILE *fp;
char *name;
public:
//void ope
CFile(char *name,char *mode=)
{
strcpy(this->name,name);
fp=fopen(name,mode);
buf=new char;
}
~CFile()
{
delete[] buf;
buf=NULL;
fclose(fp);
fp=NULL;
}
//void open();
char* getbuf()
{
return buf;
}
/* FILE *getfp()
{
return fp;
}*/
bool delete_file()
{
fclose(this->fp);
if(remove(name)==0)return 1;
else return 0;
}
void write(char *buffer)
{
fprintf(this->fp,"%s\n",buffer);
}
void read()
{
if(!feof(this->fp)
fscanf(this->fp,"%s",&this->buf);
}
/*void seek(int i)
{
fseek(this->fp,i,0);//int __cdecl fseek(FILE *_File,long _Offset,int _Origin);
}
void write()
{
fprintf(this->fp,"%s\n",this->buf);
}*/
//void
};
bool copy_file(char *old,char *New)
{
FILE *fpold=fopen(old,"rb");
FILE *fpnew=fopen(New,"wb");
if(fpold==NULL||fpnew==NULL)return 0;
int ch;
while(1)
{
ch=fgetc(fpold);
if(!feof(fpold))
{
fputc(ch,fpnew);
}
else
{
break;
}
}
fclose(fpold);
fclose(fpnew);
}
#endif
#define _CFILE_H_
#include<stdio.h>
#include<string.h>
//using namespace std;
class CFile
{
private:
char *buf;
FILE *fp;
char *name;
public:
//void ope
CFile(char *name,char *mode=)
{
strcpy(this->name,name);
fp=fopen(name,mode);
buf=new char;
}
~CFile()
{
delete[] buf;
buf=NULL;
fclose(fp);
fp=NULL;
}
//void open();
char* getbuf()
{
return buf;
}
/* FILE *getfp()
{
return fp;
}*/
bool delete_file()
{
fclose(this->fp);
if(remove(name)==0)return 1;
else return 0;
}
void write(char *buffer)
{
fprintf(this->fp,"%s\n",buffer);
}
void read()
{
if(!feof(this->fp)
fscanf(this->fp,"%s",&this->buf);
}
/*void seek(int i)
{
fseek(this->fp,i,0);//int __cdecl fseek(FILE *_File,long _Offset,int _Origin);
}
void write()
{
fprintf(this->fp,"%s\n",this->buf);
}*/
//void
};
bool copy_file(char *old,char *New)
{
FILE *fpold=fopen(old,"rb");
FILE *fpnew=fopen(New,"wb");
if(fpold==NULL||fpnew==NULL)return 0;
int ch;
while(1)
{
ch=fgetc(fpold);
if(!feof(fpold))
{
fputc(ch,fpnew);
}
else
{
break;
}
}
fclose(fpold);
fclose(fpnew);
}
#endif
[此贴子已经被作者于2019-2-14 10:15编辑过]