📄 fileoutputstream.cpp
字号:
#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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -