还嫌文件操作太麻烦? XFILE-好用的c++库(更新中~)

2 篇文章 0 订阅
2 篇文章 0 订阅

上次更新:1个月前(没什么创意,欢迎投稿)
投稿方式:评论/qq(1745488156)/gihub(xihale)

库地址:传送门
使用方法:

#include <cstdio>
#include "XFILE.h"
int main()
{
	//1.定义的时候声明打开的文件,以a+形式打开
	XFILE file("test.txt");
	//1.2定义并声明打开方式
	XFILE file("test.txt",'w');
	//1.3独立打开文件
	file.open("test.txt");
	//1.3.1独立打开并声明打开方式
	file.open("test.txt","w");
	//1.4写入内容
	file.write("HelloWorld");
	//1.5读取内容
	printf("%s",file.read());
	//1.6改变模式(慎用带w的)
	file.change_mode("a+");
	//1.7复制文件内容到XXX文件
	file.copyTo("test1.txt");
	//1.8从XXX文件复制内容到此文件
	file.copyFrom("test1.txt");
}

头:

#ifndef XFILE_H
#define XFILE_H "xfile_from_xihale"
/*
this class from xihale(https://xihale.top)
*/
class XFILE
{
	public:
		XFILE(){}
		XFILE(const char *filename)
		XFILE(const char *filename,const char *mode)
		bool open(const char *filename)
		bool open(const char *filename,const char *mode)
		bool change_mode(const char *mode)
		bool write(const char *str)
		char *read()
		bool copyTo(const char *filename)
		bool copyFrom(const char *filename)
	private:
		FILE *fp;
		char *filename;
		char *mode;
};
#endif

源码:

#ifndef XFILE_H
#define XFILE_H "xfile_from_xihale"
/*
this class from xihale(https://xihale.top)
*/
class XFILE
{
	public:
		XFILE(){}
		XFILE(const char *filename){this->open(filename);}
		XFILE(const char *filename,const char *mode){this->open(filename,mode);}
		bool open(const char *filename){return open(filename,"a+");}
		bool open(const char *filename,const char *mode)
		{
			this->filename=(char*)filename,this->mode=(char*)mode;
			fp=fopen(filename,mode);
			if(fp)return 1;
			return 0;
		}
		bool change_mode(const char *mode)
		{
			if(!fp||this->mode==mode)return 0;
			fclose(fp);
			fp=fopen(filename,mode);
			if(fp)return 1;
			return 0;
		}
		bool write(const char *str)
		{
			if(!fp)return 0;
			for(int i=0;str[i]!='\0';i++)fputc(str[i],fp);
			return 1;
		}
		char *read()
		{
			this->change_mode("r");
			if(!fp)return 0;
			static char str[10000]={0};
			int i=0;
			while((str[i++]=fgetc(fp))!=EOF);
			this->change_mode("a");
			str[i-1]='\0';
			return str;
		}
		bool copyTo(const char *filename)
		{
			if(!fp)return 0;
			this->change_mode("r");
			FILE *a=fopen(filename,"w");char ch;
			if(!a)return 0;
			while((ch=fgetc(fp))!=EOF)
				fputc(ch,a);
			return 1;
		}
		bool copyFrom(const char *filename)
		{
			this->change_mode("w");
			XFILE a(filename,"r");
			this->write(a.read());
			return 1;
		}
	private:
		FILE *fp;
		char *filename;
		char *mode;
};
#endif
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
目录....................................................................................................................................................2 说明....................................................................................................................................................3 一、使用到的开发工具:.........................................................................................................3 二、服务端开发步骤.................................................................................................................3 1、使用xfire 创建Web 服务。..............................................................................................3 2、创建服务接口和实现.........................................................................................................7 3、xfire 服务配置....................................................................................................................9 4、服务发布...........................................................................................................................10 5、为服务配置安全认证.......................................................................................................11 三、客户端开发.......................................................................................................................12 1、新建Web 工程................................................................................................................. 12 2、导入xfire 包.....................................................................................................................13 3、创建类定义.......................................................................................................................15 四、扩展1-使用xfire 插件创建客户端代码........................................................................ 18 1、插件安装.............................................................................................................................18 2、使用已安装的插件进行客户端代码生成........................................................................ 20 4、编写调用代码,调用服务.............................................................................................. 24 五、扩展2-使用axis(这时是1-4 版本)创建客户端代码.................................................... 28 1、使用WSDL2Java 工具根据WSDL 生成客户端代码.................................................. 28 2、新建工程项目...................................................................................................................30 3、编写调用代码...................................................................................................................31

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值