myfile.cpp
来自「在UBTUNTU下」· C++ 代码 · 共 75 行
CPP
75 行
#include <string.h>
#include "MyFile.h"
CMyFile::CMyFile()
{
m_hFile=NULL;
}
CMyFile::~CMyFile()
{
Close();
}
bool CMyFile::Open(const char *pszFileName,
const char *pszMode)
{
Close();
m_hFile=fopen(pszFileName,pszMode);
return m_hFile != NULL;
}
//将文件描述符转变成文件指针
bool CMyFile::Open(int fd,const char *pszMode)
{
Close();
m_hFile=fdopen(fd,pszMode);
return m_hFile != NULL;
}
int CMyFile::Read(void *pvData,int iSize)
{
return fread(pvData,1,iSize,m_hFile);
}
//从文件中读取一行
char *CMyFile::ReadLine(char *pszLine,int iMaxSize)
{
return fgets(pszLine,iMaxSize,m_hFile);
}
int CMyFile::Write(const void *pvData,int iSize)
{
return fwrite(pvData,1,iSize,m_hFile);
}
//往文件中写入一个字符串
int CMyFile::Write(const char *pszData)
{
return fputs(pszData,m_hFile);
}
bool CMyFile::IsEof()
{
return feof(m_hFile) != 0;
}
bool CMyFile::Seek(int iSize,int iMode)
{
return fseek(m_hFile,iSize,iMode) == 0;
}
bool CMyFile::IsOpened()
{
return m_hFile != NULL;
}
void CMyFile::Close()
{
if(m_hFile != NULL)
{
fclose(m_hFile);
m_hFile=NULL;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?