【c++基础】ifstream的构造函数

网友投稿 669 2022-11-01

【c++基础】ifstream的构造函数

【c++基础】ifstream的构造函数

公共成员函数:

default (1) ifstream();initialization (2) explicit ifstream (const char* filename, ios_base::openmode mode = ios_base::in);explicit ifstream (const string& filename, ios_base::openmode mode = ios_base::in);copy (3) ifstream (const ifstream&) = delete;move (4) ifstream (ifstream&& x);

mode

member constant

stands for

access

in*

input

File open for reading: the ​internal stream buffer

out

output

File open for writing: the ​internal stream buffer

binary

binary

Operations are performed in binary mode rather than text.

ate

at end

The output position starts at the end of the file.

app

append

All output operations happen at the end of the file, appending to its existing contents.

trunc

truncate

Any contents that existed in the file before it is open are discarded.

code

// ifstream constructor.#include // std::cout#include // std::ifstreamint main () { std::ifstream ifs ("test.txt", std::ifstream::in); char c = ifs.get(); while (ifs.good()) { std::cout << c; c = ifs.get(); } ifs.close(); return 0;}

参考

1.​​cplusplus.com​​;

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:x86/ARM/MIPS的交互式反汇编程序, 生成语法着色缩进的伪代码
下一篇:SQLPad 一个Web应用程序,用于编写和运行SQL查询并可视化结果
相关文章

 发表评论

暂时没有评论,来抢沙发吧~