Fstream包含了ofstream和ifstream的所有内容

Fstream contain all the content of ofstream and ifstream?

本文关键字:ifstream 包含 ofstream Fstream      更新时间:2023-10-16

如果两者都可以使用std::fstream,为什么我们要使用std;:ofstream作为输出,使用std::ifstream作为输入?

这与stringstream、istingstream和ostingstream(链接)的情况类似。

通常,您不同时从同一个流中读取和写入,因此使用ifstream和ofstream更容易,因为您不必担心流状态和流位置(就像fstream的情况一样)。