E
class CApplication
{
private:
std::vector< char >m_vContent;
int m_iSize;
afx_msg int ReadContent( CString name );
afx_msg int WriteContent( CString name );
public:
afx_msg int ReadWrite( CString oldcs, CString newcs );
CApplication(){
m_iSize = 0;
}
};
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
CApplication capp;
int iRet = capp.ReadWrite( "entries.txt", "ue.txt" )
return iRet;
}
int CApplication::ReadWrite( CString oldcs, CString newcs )
{
int iRet = ReadContent( oldcs );
if( iRet == 0 )
iRet = WriteContent( newcs );
return iRet
}
int CApplication::ReadContent( CString name )
{
CFileException ex;
CFile cfile;
if( cfile.Open( name, CFile::modeRead | CFile::typeBinary, &ex ) )
{
const int iSIZE = 512;
char bBuffer[ iSIZE ] = { '\0' };
UINT uiRead =0;
while( uiRead = cfile.Read( bBuffer, iSIZE ) )
{
if( uiRead <= iSIZE ){
m_vContent.insert( m_vContent.end(), &bBuffer[0], &bBuffer[uiRead] );
m_iSize += uiRead;
}
}
cfile.Close();
}
else
{
TCHAR szCause[255];
ex.GetErrorMessage(szCause, 255);
_tprintf( szCause );
return -1;
}
return 0;
}
int CApplication::WriteContent( CString name )
{
CFile newfile;
CFileException ex;
if( newfile.Open( name, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary ) )
{
newfile.Write( m_vContent, ( m_iSize-1 ) );
newfile.Close();
return OK;
}
else
{
TCHAR szCause[255];
ex.GetErrorMessage(szCause, 255);
_tprintf( szCause );
return -1;
}
return 0;
}
// untested - ausn kopf geschrieben