std::basic_filebuf::open
来自cppreference.com
< cpp | io | basic filebuf
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
std::basic_filebuf<CharT, Traits>* open( const char* s, std::ios_base::openmode mode ) |
(1) | |
std::basic_filebuf<CharT, Traits>* open( const std::string& s, std::ios_base::openmode mode ) |
(2) | (C++11 起) |
打开这个文件,它的名字是由
1) 原文:
Opens the file whose name is given by
null结尾的窄字节的字符串,
2) s
原文:
the null-terminated narrow byte string
s
null结尾的窄字节的字符串,s.c_str()
原文:
the null-terminated narrow byte string s.c_str()
作为如果通过调用std::fopen(s, modestring),
modestring
如下:原文:
as if by calling std::fopen(s, modestring), where
modestring
is determined as follows: modestring
|
openmode & ~ate |
"r" | in
|
"w" | out , out|trunc
|
"a" | app , out|app
|
"r+" | out|in |
"w+" | out|in|trunc |
"a+" | out|in|app, in|app |
"rb" | binary|in |
"wb" | binary|out, binary|out|trunc |
"ab" | binary|app, binary|out|app |
"r+b" | binary|out|in |
"w+b" | binary|out|in|trunc |
"a+b" | binary|out|in|app, binary|in|app |
如果
openmode
是未列出的模式之一,open()
失败.原文:
If
openmode
is not one of the modes listed, the open()
fails.如果打开操作成功,openmode & std::ios_base::ate != 0(
ate
位),该文件重新定位到文件末尾的位置,如果通过调用std::fseek(file, 0, SEEK_END)。如果重新定位失败,调用close()
,并返回一个空指针来表示失败.原文:
If the open operation succeeds and openmode & std::ios_base::ate != 0 (the
ate
bit is set), repositions the file position to the end of file, as if by calling std::fseek(file, 0, SEEK_END). If the repositioning fails, calls close()
and returns a null pointer to indicate failure.如果相关的文件已经打开,则返回一个空指针马上.
原文:
If the associated file was already open, returns a null pointer right away.
目录 |
[编辑] 参数
s | - | 打开的文件名
|
openmode | - | 文件打开模式,二进制或(OR)的std::ios_base模式
原文: the file opening mode, a binary OR of the std::ios_base modes |
[编辑] 返回值
*this成功,一个空指针,失败.
原文:
*this on success, a null pointer on failure.
[编辑] 注释
open()
通常是通过调用构造函数或open()
成员函数std::basic_fstream.原文:
open()
is typically called through the constructor or the open()
member function of std::basic_fstream.[编辑] 示例
本章尚未完成 原因:暂无示例 |
[编辑] 另请参阅
checks if the associated file is open (公共成员函数) | |
冲放区的缓冲区和关闭相关的文件 原文: flushes the put area buffer and closes the associated file (公共成员函数) |