xfile.cpp

来自「该程序是用vc开发的对动态数组进行管理的DLL」· C++ 代码 · 共 2,282 行 · 第 1/3 页

CPP
2,282
字号
#include "xfile.h"/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*//*@@@@@@@@@@@@@@@@@@@@@@	Xio			   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@*//*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/Xio cio;Xio &  Xio::operator<<( unsigned char uch ){	printf("%c",uch  );	return *this;}Xio &  Xio::operator<<( signed char sch ){	printf("%c",sch  );	return *this;}Xio &  Xio::operator<<(  char* psz ){	printf("%s",psz  );		return *this;}Xio &  Xio::operator<<(  unsigned char* pusz ){	printf("%s",pusz  );	return *this;}Xio &  Xio::operator<<(  signed char* pssz ){	printf("%s",pssz  );		return *this;}Xio &  Xio::operator<<( short s  ){	printf("%d",s  );	return *this;}Xio &  Xio::operator<<( unsigned short us  ){	printf("%d",us  );		return *this;}Xio &  Xio::operator<<( int n  ){	printf("%d",n  );	return *this;}Xio &  Xio::operator<<( unsigned int un ){	printf("%d",un  );		return *this;}Xio &  Xio::operator<<( long l ){	printf("%ld",l  );	 	return *this;}Xio &  Xio::operator<<( unsigned long ul ){	printf("%ld",ul);	return *this;}Xio &  Xio::operator<<( float f  ){	printf("%f",f);	 	return *this;}Xio &  Xio::operator<<( double d  ){	printf("%e",d );	return *this;}Xio &   Xio::operator<<( XString & xstr ){	*this<<xstr.m_pString;		return *this;}Xio &   Xio::operator>>( XString & xstr ){	char tmp[10000];	*this>>tmp;	xstr=tmp;	return *this;}Xio &  Xio::operator>>( char* psz ){	scanf("%s",psz);	return *this;}Xio &  Xio::operator>>( unsigned char* pusz ){	scanf("%s",pusz);	return *this;}Xio &  Xio::operator>>( signed char* pssz ){	scanf("%s",pssz);		return *this;}Xio &  Xio::operator>>( char& rch ){	scanf("%c",&rch);	return *this;}Xio &  Xio::operator>>( unsigned char& ruch ){	scanf("%c",&ruch);		return *this;}Xio &  Xio::operator>>( signed char& rsch ){	scanf("%c",&rsch);		return *this;}Xio &  Xio::operator>>( short & s ){	scanf("%hd",&s);	return *this;}Xio &  Xio::operator>>( unsigned short& us ){	scanf("%hd",&us);	return *this;}Xio &  Xio::operator>>( int& n ){	scanf("%d",&n);		return *this;}Xio &  Xio::operator>>( unsigned int& un ){	scanf("%d",&un);	return *this;}Xio &  Xio::operator>>( long& l ){	scanf("%ld",&l);	return *this;}Xio &  Xio::operator>>( unsigned long& ul ){	scanf("%ld",&ul);		return *this;}Xio &  Xio::operator>>( float& f ){	scanf("%f",&f);		return *this;}Xio &  Xio::operator>>( double& d ){	scanf("%lf",&d);	return *this;}Xio &  Xio::operator<<( char ch1 ){	printf("%c" , ch1  );	return *this;}/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*//*@@@@@@@@@@@@@@@@@@@@@@	XFile   	   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@*//*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/FILE * XFile::FP(){	return fp;}XFile::XFile(){	fp=NULL;	strcpy(FileType,"");	strcpy(FileName,"");} XFile::~XFile(){	close();}void XFile::close(){	if(fp!=NULL)	{		fclose(fp);		fp=NULL;	}} int XFile::rewind(){	return toBeg();}int  XFile::gettext(char *str){		toBeg();		memset(str,'\0',length());		char tmp[300];		while(getline(tmp,300))		{			strcat(str,tmp);			strcat(str,"\n");		}		str[strlen(str) - 1]='\0';		return 1;}int XFile::open(char *path , char * mode  ){	close();	strcpy(FileType,"");	strcpy(FileName,"");	fp=fopen(path,mode);	if(fp==NULL)	{		printf("%s process(%s) error!\n",path,mode);		return 0;	}	strcpy(FileName,path);	strcpy(FileType,mode);	return 1;}int XFile::openr(char *path){	return open(path,"r");}int XFile::openw(char *path){	return open(path,"w");	}int XFile::openrb(char *path){	return open(path,"rb");}int XFile::openwb(char *path){	return open(path,"wb");	}int XFile::write(void *data,int size){	return fwrite(data,size,1,fp);}int XFile::read(void *data,int size){	return fread(data,size,1,fp);}XFile &  XFile::operator>>( char* psz ){	fscanf(fp,"%s",psz);	return *this;}XFile &  XFile::operator>>( unsigned char* pusz ){	fscanf(fp,"%s",pusz);	return *this;}XFile &  XFile::operator>>( signed char* pssz ){	fscanf(fp,"%s",pssz);	return *this;}XFile &  XFile::operator>>( char& rch ){	fscanf(fp,"%c",&rch);	return *this;}XFile &  XFile::operator>>( unsigned char& ruch ){	fscanf(fp,"%c",&ruch);	return *this;}XFile &  XFile::operator>>( signed char& rsch ){	fscanf(fp,"%c",&rsch);	return *this;}XFile &  XFile::operator>>( short& s ){	fscanf(fp,"%hd",&s);	return *this;}XFile &  XFile::operator>>( unsigned short& us ){	fscanf(fp,"%hd",&us);	return *this;}XFile &  XFile::operator>>( int& n ){	fscanf(fp,"%d",&n);	return *this;}XFile &  XFile::operator>>( unsigned int& un ){	fscanf(fp,"%d",&un);	return *this;}XFile &  XFile::operator>>( long& l ){	fscanf(fp,"%ld",&l);	return *this;}XFile &  XFile::operator>>( unsigned long& ul ){	fscanf(fp,"%ld",&ul);	return *this;}XFile &  XFile::operator>>( float& f ){	fscanf(fp,"%f",&f);	return *this;}XFile &  XFile::operator>>( double& d ){	fscanf(fp,"%lf",&d);	return *this;}XFile &  XFile::operator<<( char ch1 ){	fprintf(fp,"%c" , ch1  );	return *this;}XFile &  XFile::operator<<( unsigned char uch ){	fprintf(fp,"%c",uch);	return *this;}XFile &  XFile::operator<<( signed char sch ){	fprintf(fp,"%c",sch  );	return *this;}XFile &  XFile::operator<<(  char* psz ){	fprintf(fp,"%s",psz  );	return *this;}XFile &  XFile::operator<<(  unsigned char* pusz ){	fprintf(fp,"%s",pusz  );	return *this;}XFile &  XFile::operator<<(  signed char* pssz ){	fprintf(fp,"%s",pssz  );	return *this;}XFile &  XFile::operator<<( short s  ){	fprintf(fp,"%d",s  );	return *this;}XFile &  XFile::operator<<( unsigned short us  ){	fprintf(fp,"%d",us  );	return *this;}XFile &  XFile::operator<<( int n  ){	fprintf(fp,"%d",n  );	return *this;}XFile &  XFile::operator<<( unsigned int un ){	fprintf(fp,"%d",un  );	return *this;}XFile &  XFile::operator<<( long l ){	fprintf(fp,"%ld",l  );	return *this;}XFile &  XFile::operator<<( unsigned long ul ){	fprintf(fp,"%ld",ul  );	return *this;}XFile &  XFile::operator<<( float f  ){	fprintf(fp,"%e",f  );	return *this;}XFile &   XFile::operator>>( XString & xstr ){	xstr.setWidth(500);	*this>>xstr.m_pString;	return *this;}XFile &   XFile::operator <<( XString & xstr ){	*this<<xstr.m_pString;		return *this;}XFile &  XFile::operator<<( double d  ){	fprintf(fp,"%e ",d );	return *this;}long XFile::tell(){	return ftell(fp);	}int XFile::seek(long off,int From){	if(From < 0 || From > 2)	{		cio<<"seek FromPosition error!!!"<<enter;		return -1;	}		return fseek(fp,off,From);}int XFile::toCur(long cur){	return fseek(fp,cur,0);}int XFile::toEnd(){	return fseek(fp,0,2);}int XFile::toBeg(){	return fseek(fp,0,0);		}long XFile::length(){	long cur=ftell(fp);	fseek(fp,0,2);	long len1=ftell(fp);	toCur(cur);	return len1;}bool XFile::getline( char* psz ,int maxlen, char delim ){	memset(psz,'\0',maxlen);	char ch;	int i=0;	if(feof(fp))			return false;	while(1)	{			(*this)>>ch;		if(feof(fp))			break;		if(ch!=delim)		{			psz[i]=ch;			i++;		}		else			break;	}	return true;}/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*//*@@@@@@@@@@@@@@@@@@@@@@	XFileAsc	   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@*//*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/XFileAsc &  XFileAsc::operator>>( char* psz ){	xfile>>psz;	return *this;}XFileAsc &  XFileAsc::operator>>( unsigned char* pusz ){	xfile>>pusz;	return *this;}XFileAsc &  XFileAsc::operator>>( signed char* pssz ){	xfile>>pssz;	return *this;}XFileAsc &  XFileAsc::operator>>( char& rch ){	xfile>>rch;	return *this;}XFileAsc &  XFileAsc::operator>>( unsigned char& ruch ){	xfile>>ruch;	return *this;}XFileAsc &  XFileAsc::operator>>( signed char& rsch ){	xfile>>rsch;	return *this;}XFileAsc &  XFileAsc::operator>>( short& s ){	xfile>>s;	return *this;}XFileAsc &  XFileAsc::operator>>( unsigned short& us ){	xfile>>us;	return *this;}XFileAsc &  XFileAsc::operator>>( int& n ){	xfile>>n;	return *this;}XFileAsc &  XFileAsc::operator>>( unsigned int& un ){	xfile>>un;	return *this;}XFileAsc &  XFileAsc::operator>>( long& l ){xfile>>l;	return *this;}XFileAsc &  XFileAsc::operator>>( unsigned long& ul ){	xfile>>ul;	return *this;}XFileAsc &  XFileAsc::operator>>( float& f ){	xfile>>f;	return *this;}XFileAsc &  XFileAsc::operator>>( double& d ){	xfile>>d;	return *this;}XFileAsc &  XFileAsc::operator<<( char ch1 ){	xfile<<ch1;	return *this;}XFileAsc &  XFileAsc::operator<<( unsigned char uch ){	xfile<<uch;	return *this;}XFileAsc &  XFileAsc::operator<<( signed char sch ){	xfile<<sch;	return *this;}XFileAsc &  XFileAsc::operator<<(  char* psz ){	xfile<<psz;	return *this;}XFileAsc &  XFileAsc::operator<<(  unsigned char* pusz ){	xfile<<pusz;	return *this;}XFileAsc &  XFileAsc::operator<<(  signed char* pssz ){	xfile<<pssz;	return *this;}XFileAsc &  XFileAsc::operator<<( short s  ){	xfile<<s;	return *this;}XFileAsc &  XFileAsc::operator<<( unsigned short us  ){	xfile<<us;	return *this;}XFileAsc &  XFileAsc::operator<<( int n  ){	xfile<<n;	return *this;}XFileAsc &  XFileAsc::operator<<( unsigned int un ){	xfile<<un;	return *this;}XFileAsc &  XFileAsc::operator<<( long l ){	xfile<<l;	return *this;}XFileAsc &  XFileAsc::operator<<( unsigned long ul ){	xfile<<ul;	return *this;}XFileAsc &  XFileAsc::operator<<( float f  ){	xfile<<f;	return *this;}XFileAsc &   XFileAsc::operator>>( XString & xstr ){	xstr.setWidth(1000);	*this>>xstr.m_pString;	return *this;}XFileAsc &   XFileAsc::operator <<( XString & xstr ){	*this<<xstr.m_pString;		return *this;}XFileAsc &  XFileAsc::operator<<( double d  ){	xfile<<d;	return *this;}bool XFileAsc::getline( char* psz ,int maxlen, char delim ){	return xfile.getline(psz,maxlen,delim);}int  XFileAsc::gettext(char *str){		return xfile.gettext(str);}XFileAsc::XFileAsc(){} XFileAsc::~XFileAsc(){	close();} void XFileAsc::close() {	 xfile.close(); }int   XFileAsc::openr(char *path){	return xfile.openr( path);}int   XFileAsc::openw(char * path){	return xfile.openw( path);		}void XFileAsc::go(long n){	char  d[1000];	memset(d,'\0',1000);	rewind();	for(long i=0;i<n;i++)	{		xfile>>d;	}}	int   XFileAsc::read( short *s ,int len ){	int i;	for(i=0;i<len;i++)	{		xfile>>s[i];	}	return 1;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?