fstream,ofstream,ostream,iostream之间的区别
Difference between fstream, ofstream, ostream, iostream
我正在C++的入门级课程上进行测验,我正在尝试理解一个问题。 在互联网上搜索并没有得到答案后,所以我来了。
Which of the following function declarations will accept either cout or a file stream
object as its argument?
A. void output( fstream &outFile);
B. void output( ofstream &outFile);
C. void output( ostream &outFile);
D. void output( iostream &outFile);
答案是C。
我知道以下两者之间的区别:fstream,ofstream,ostream,iostream。
我不明白的是为什么其他选项都无法接受 cout 或文件流对象作为参数。
答案是否像 ostream 对象包含可以作为参数传递的数据(字符等)一样简单?
任何信息将不胜感激。
答案是C。问题是关于继承层次结构。 std::cout
是std::ostream
的一个实例。所有其他函数都接受 std::ostream 的子类,因此无法处理 std::cout
。 std::fstream
可以传递给他们所有人,但问题是关于两者的。
相关文章:
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- int(c) 和 c-'0' 之间的区别。C++
- C++ 使用 assign 函数的字符串与直接使用 '=' 更改值的字符串之间的区别
- std::atomic和std::condition_variable wait,notify_*方法之间的区别
- 我是C++编程的新手,这些代码之间有什么区别,我应该使用哪一个
- 在 const 函数中通过引用和指针返回之间的区别
- 我想知道长双倍和双倍之间的区别
- 这 4 个 lambda 表达式之间有什么区别?
- 结构体 S { int align; } 之间的区别;(struct 关键字后的名称)和 struct { int al
- (double) 和 double() 之间的区别
- & 和 * 之间的区别
- std::is_convertible 和 std::convertible_to 之间的区别(在实践中)?
- 析构函数和'delete'之间的区别
- 在 typedef 内部使用 const 关键字和在 typedef 外部使用 const 关键字之间有区别吗?
- 从预序遍历构造 bst 的 c++ 和 python 解决方案之间的区别
- vector.back() 和 vector[vector.size() - 1] 之间的区别?
- 空指针常量 (nullptr)、空指针值和空成员指针值之间有什么区别?
- 函数签名与调用的函数不匹配,常量字符[]和字符*之间的区别?
- OpenMP #pragma omp for v/s #pragma omp parallel for 之间的区别?
- S() 与 S{} 之间的区别?