当前位置 : 主页 > 编程语言 > java >

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

来源:互联网 收集:自由互联 发布时间:2022-07-13
公共成员函数: 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) i

公共成员函数:

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 <iostream> // std::cout
#include <fstream> // std::ifstream

int 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​​;

上一篇:java限制方法执行时间;Future使用
下一篇:没有了
网友评论