⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileoperation.h

📁 实时监控
💻 H
字号:
// fileoperation.h: interface for the Cfileoperation class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_FILEOPERATION_H__05819236_652F_4757_A8F0_C0E881770456__INCLUDED_)
#define AFX_FILEOPERATION_H__05819236_652F_4757_A8F0_C0E881770456__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

template <class t> 
class Cfileoperation  
{
public:
	Cfileoperation() { ;}
	virtual ~Cfileoperation() {;}

	int openfile(char* m_path,char* m_param,t m_tem[]);
	int openfile(char* m_path,char* m_param,t m_tem[], int length);
	void savefile(char* m_path,char* m_param,t m_tem[],int m_length);
    void savefilename(char* m_path,char* m_param,t m_tem[],int m_length);


};
template <class t>  
int Cfileoperation<t>::openfile(char* m_path,char* m_param,t m_tem[])
{
    FILE *m_file;
    m_file=fopen(m_path,m_param);
	if(m_file==NULL)
	{
		AfxMessageBox(IDS_OPEN_FILE);
		return 0;
	}
	ZeroMemory(m_tem, sizeof(t)*120);
	for(int i=0; ;i++)
	{
		if(fread(&m_tem[i],sizeof(t),1,m_file)!=1)
		{
			fclose(m_file);
			return i;
		}
	}
	fclose(m_file);
}

template <class t>  
int Cfileoperation<t>::openfile(char* m_path,char* m_param,t m_tem[], int length)
{
    FILE *m_file;
    m_file=fopen(m_path,m_param);
	if(m_file==NULL)
	{
		AfxMessageBox(IDS_OPEN_FILE);
		return 0;
	}
	ZeroMemory(m_tem, sizeof(t)*length);
	for(int i=0; ;i++)
	{
		if(fread(&m_tem[i],sizeof(t),1,m_file)!=1)
		{
			fclose(m_file);
			return i;
		}
	}
	fclose(m_file);
}


template <class t>
void Cfileoperation<t>::savefile(char* m_path,char* m_param,t m_tem[],int m_length)
{
	FILE *m_file;
    m_file=fopen(m_path,m_param);
	if(m_file==NULL)
	{
		AfxMessageBox(IDS_WRITE_FILE);
	}
	for(int i=0;i<m_length;i++)
	{
		if(fwrite(&m_tem[i],sizeof(t),1,m_file)!=1)
		{
			fclose(m_file);
			return;
		}
	}
	fclose(m_file);

}
template <class t>
void Cfileoperation<t>::savefilename(char* m_path,char* m_param,t m_tem[],int m_length)
{
	FILE *m_file;
    m_file=fopen(m_path,m_param);
	if(m_file==NULL)
	{
		AfxMessageBox(IDS_WRITE_FILE);
	}
	for(int i=0;i<m_length;i++)
	{
		if(!strcmp(m_tem[i].name,"")) continue;
		if(fwrite(&m_tem[i],sizeof(t),1,m_file)!=1)
		{
			fclose(m_file);
			return;
		}
	}
	fclose(m_file);
}
#endif // !defined(AFX_FILEOPERATION_H__05819236_652F_4757_A8F0_C0E881770456__INCLUDED_)

⌨️ 快捷键说明

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