cout不使用ostream头文件

Aak*_*rma 0 c++ cout ostream

我读过cout是ostream的一个对象......

但为什么这个代码

#include<ostream>
using namespace std;

int main()
{
cout << "ostream included!" << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)

抛出错误: -

practice1.cpp: In function 'int main()':
practice1.cpp:6:1: error: 'cout' was not declared in this scope
cout << "ostream included!" << endl;
^~~~
Run Code Online (Sandbox Code Playgroud)

我的理解是错误还是有其他错误?(MinGW windows 10)

提前致谢!

Luc*_*cio 6

描述

为什么这不起作用的原因是因为cout是OStream类型但是在IOStream标头内.因此,要获得定义,cout您需要包含iostream库而不是ostream类.

正如OriBS所提到iostreamostream,包括而不是.

参考