#include <io.h>
class CReadFileAll
{
public:
CReadFileAll()
{
m_pstr=0;
m_nbuflen=0;
}
~CReadFileAll()
{
if (m_pstr!=0)
{
delete m_pstr;
m_pstr=0;
}
}
bool get_file_txt(const char*pfilename,char**pst,int &nlen)
{
if(0==pfilename) return false;
CFile f;
if (f.Open(pfilename,CFile::modeRead)==FALSE)
{
return false;
}
//判断大小
if (m_nbuflen<f.GetLength()+10)
{
if(m_pstr) delete m_pstr;
m_pstr=new char[f.GetLength()+10];
m_nbuflen=f.GetLength()+10;
}
f.Read(m_pstr,f.GetLength());
m_pstr[f.GetLength()]=0;
(*pst)=m_pstr;
nlen=f.GetLength();
f.Close();
return true;
}
private:
char *m_pstr;
int m_nbuflen;
};
/
class CMaxBuf
{
public:
CMaxBuf()
{
m_str=0;
m_nlen=0;
}
~CMaxBuf()
{
if (m_str)
{
delete m_str;
m_str=0;
}
}
char *get_buf(int nbuflen)
{
if (m_nlen<nbuflen)
{
if(m_str) delete m_str;
m_str=new char[nbuflen];
m_nlen=nbuflen;
}
return m_str;
}
private:
char *m_str;
int m_nlen;
};