※C++随笔※=>☆C++基础☆=>※№ C++文件操作 (fstream)(八)

2014-11-24 07:22:03 · 作者: · 浏览: 11
nter in the file last. Can change the position of the pointer, often used in combination and in, out
static const WORD MODEL_APP = std::ios::app; // 0x08, for writing, the file does not exist, to create, to write new content after the original contents of the file if the file already exists, the total in the final pointer position
static const WORD MODEL_TRUNC = std::ios::trunc; // 0x10, length of the file read and write before first truncated to 0 (default)
static const WORD MODEL_NOCREATE = std::ios::_Nocreate; // 0x20, file does not exist error, often used in combination and in or app
static const WORD MODEL_NOREPLACE = std::ios::_Noreplace; // 0x40, file exists generates an error when used in combination, often and out
static const WORD MODEL_BINARY = std::ios::binary; // 0x80, binary format file
* @param WORD wAccess
static const WORD ACCESS_ORDINARY = 0; // 0: ordinary files, open access
static const WORD ACCESS_READONLY = 1; // 1: read-only file
static const WORD ACCESS_HIDDEN = 2; // 2: hidden file
static const WORD ACCESS_SYSTEM = 4; // 4: System Files
* @return VOID
* @note Note the slash in the path name to dual-write, such as: "\\MyFiles\\ReadMe.txt"
* @attention The default way to open a file to open the binary file reading and writing
*/
VOID
AL_File::Open(const NCHAR* cpFilePath, WORD wOpenModel, WORD wOpenAccess)
{
if (NULL == m_pfstream) {
return;
}
m_pfstream->open(cpFilePath, wOpenModel, wOpenAccess);
}
////////////////////////////////Check if successfully opened//////////////////////////////////////////
/**
* Good (Check if successfully opened)
*
* @param VOID
* @return BOOL
* @note
* @attention
*/
BOOL
AL_File::Good(VOID)
{
if (NULL == m_pfstream) {
return FALSE;
}
return m_pfstream->good();
}
/**
* Fail (Check if successfully opened)
*
* @param VOID
* @return BOOL
* @note
* @attention
*/
BOOL
AL_File::Fail(VOID)
{
if (NULL == m_pfstream) {
return FALSE;
}
return m_pfstream->fail();
}
/**
* IsOpen (Check if successfully opened)
*
* @param VOID
* @return BOOL
* @note Generally use this method to determine if a file is open successfully
* @attention
*/
BOOL
AL_File::IsOpen(VOID)
{
if (NULL == m_pfstream) {
return FALSE;
}
return m_pfstream->is_open();
}
/////////////////////////////////Reading and writing binary files/////////////////////////////////////////
/**
* Put (Reading and writing binary files)
*
* @param NCHAR ch
* @return VOID
* @note put () function to write to the stream a character prototype ofstream & put (char ch),
the use of relatively simple, such as file1.put ('c'); is to write to the stream a character 'c'.
* @attention
*/
VOID
AL_File::Put(NCHAR ch)
{
if (NULL == m_pfstream) {
return;
}
m_pfstream->put(ch);
}
/**
* Get (Reading and writing binary files)
*
* @param NCHAR& ch
* @return VO