fileoutputstream.cpp
来自「一个symbian 冒险游戏代码」· C++ 代码 · 共 50 行
CPP
50 行
#include <io/FileOutputStream.h>
#include <io/FileNotFoundException.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <config.h>
using namespace lang;
namespace io
{
FileOutputStream::FileOutputStream( const String& filename ) :
m_filename( filename )
{
char buf[1000];
String::cpy( buf, sizeof(buf), filename );
m_fh = fopen( buf, "wb" );
if ( !m_fh )
throwError( FileNotFoundException( Format("Failed to open {0}", filename) ) );
}
FileOutputStream::~FileOutputStream()
{
FILE* fh = reinterpret_cast<FILE*>(m_fh);
if ( fh )
fclose( fh );
}
void FileOutputStream::write( const void* data, int size )
{
FILE* fh = reinterpret_cast<FILE*>(m_fh);
int bytes = fwrite( data, 1, size, fh );
if ( bytes < size && ferror(fh) )
throwError( IOException( Format("Failed to write {1} bytes to {0}", toString(), size) ) );
}
lang::String FileOutputStream::toString() const
{
return m_filename;
}
} // io
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?