如果 cout 包含在我的标头中,为什么在我的 cpp 中未定义?
Why is cout undefined in my cpp if it's included in my header?
我有一个类A.h,它有#include iostream
则在B.h I #中包含A.h
则在C.h中包含B.h
在C.cpp中,我将print()函数定义为void C::print() const {
cout << "C has specs of: " << getSpecs() << endl;
}
C.cpp的计数是未定义的,为什么?
我认为,既然iostream包含在A.h中,既然B.h包含A.h,而C.h包含B.h,那么在我的c.p中应该包含iostream。
有没有办法完成这个没有#包括iostream在我所有的。h ?
cout
在命名空间std
中。用std::cout
和std::endl
代替cout
和endl
与@fuzzything44的答案一起使用
using namespace::std;
放在你的。cpp文件的顶部,或者甚至把它放在一个通用的头文件中。
这样做的缺点是,如果你包含了很多头文件,并使用namespace:xyz;声明;
相关文章:
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 我的字符计数代码计算错误.为什么
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 为什么我的代码在输出中增加了93天
- 为什么我的for循环不能正确获取argv
- 为什么二进制搜索在我的测试中不起作用
- 当我在main中声明了我的2d数组时,为什么我的程序会退出
- 为什么我的 std::ref 无法按预期工作?
- 为什么我的删除节点函数实际上没有删除节点?
- 为什么我的 IExtractIcon 处理程序没有被调用?
- 为什么我的多线程作业队列崩溃
- 为什么我的排序算法会更改数组值
- 为什么我的变量没有更新,我的 LED 没有亮起?
- 为什么在我的函数类型后使用引用运算符 (&) 允许我修改它返回的值?
- 为什么我的程序在for循环中k=0时返回垃圾值
- 为什么它只打印双链接列表的第一个值,而我的程序却崩溃了
- 为什么我的点没有在 OpenGL 中绘制鼠标所在的位置?
- 为什么我的共享库中存在展开符号
- 为什么我的C++代码中出现'Segmentation Fault: 11'行?
- 为什么我的递归函数按降序打印,然后按升序打印?