COUT不使用Ostream标头文件
cout not working with ostream header file
我读到Cout是Ostream的对象...
但是为什么此代码
#include<ostream>
using namespace std;
int main()
{
cout << "ostream included!" << endl;
return 0;
}
扔错误: -
practice1.cpp: In function 'int main()':
practice1.cpp:6:1: error: 'cout' was not declared in this scope
cout << "ostream included!" << endl;
^~~~
我的理解是错误的还是还有其他错误?(Mingw Windows 10)
预先感谢!
描述
原因不起作用的原因是cout
是类型Ostream,但位于iostream标题内。因此,要获取cout
的定义,您需要包括iostream
库,而不是ostream
类。
解决方案
包括iostream
而不是ostream
,如提到的Oribs。
参考
- 在iostream对象列表中找到的对象
cout
-
"包括
iostream
自动还包括ostream
... -
"标准对象cout,cerr和clog是这种类型的对象。"请参阅http://www.cplusplus.com/reference/ostream/ostream/
您应该包括iostream
#include <iostream>
相关文章:
- .cpp和.h文件中的模板专用化声明
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 文本文件中的单词链表
- CMake-按正确顺序将项目与C运行时对象文件链接
- 使用新行和不使用新行读取文件
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- ostream:在 cout 或文件上输出的类
- 如何访问标准::ostream 文件
- 尝试使用 ostream 保存文件内容时出错
- 将带有C++的二进制文件从 istream 复制到 ostream 并不总是正确的
- 在Ostream上使用std :: endl使我的文件二进制
- COUT不使用Ostream标头文件
- 超载Ostream运算符从文件打印矩阵
- 错误:无法在实现文件中绑定“std::ostream”
- 输出到stdout和带有cout、cerr、clog甚至用户定义的ostream的文件
- 对象文件中的ostream操作符发生了什么?
- 如何用打开的文件将ostream内容写入ofstream
- ostream打开文件失败,因为打开的文件太多
- 如何在c++和linux中将std::ostream重定向到文件或/dev/null
- 创建ostream到文件或cout的正确方法