【发布时间】:2015-08-03 23:45:18
【问题描述】:
在处理文件时,以下两个示例中的哪个是首选? 一个提供比另一个更好的性能吗?有什么区别吗?
ifstream input("input_file.txt");
ofstream output("output_file.txt");
对
fstream input("input_file.txt",istream::in);
fstream output("output_file.txt",ostream::out);
【问题讨论】:
-
使用
istream预期ostream会导致错误,如果您不小心使用在输入模式下打开的fstream,编译器不会抱怨。
标签: c++ fstream ifstream ofstream