std::ios_base::openmode
来自cppreference.com
typedef/* 由实现定义 */ openmode; | ||
staticconstexpr openmode app = /* 由实现定义 */; staticconstexpr openmode binary = /* 由实现定义 */; | ||
staticconstexpr openmode noreplace =/* 由实现定义 */; | (C++23 起) | |
指定可用的文件打开标志。它是一种位掩码类型(BitmaskType) ,定义了下列常量:
常量 | 解释 |
app | 每次写入前寻位到流结尾 |
binary | 以二进制模式打开 |
in | 为读打开 |
out | 为写打开 |
trunc | 在打开时舍弃流的内容 |
ate | 打开后立即寻位到流结尾 |
noreplace(C++23) | 以独占模式打开 |
[编辑]示例
运行此代码
#include <fstream>#include <iostream>#include <string> int main(){constchar* fname ="unique_name.txt"; // 写入临时流对象std::fstream(fname, std::ios::out| std::ios::trunc)<<"Hi"; std::string s;std::fstream(fname, std::ios::in)>> s;std::cout<< s <<'\n';}
输出:
Hi
[编辑]参阅
打开文件并配置它为关联字符序列 ( std::basic_filebuf<CharT,Traits> 的公开成员函数) | |
构造一个 basic_stringbuf 对象 ( std::basic_stringbuf<CharT,Traits,Allocator> 的公开成员函数) |