本文介绍了cout 不是 std 的成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在练习使用多个文件和头文件等.所以我有这个项目,它需要两个数字然后将它们相加.很简单.
I'm practicing using mulitple files and header files etc. So I have this project which takes two numbers and then adds them. Pretty simple.
这是我的文件:
main.cpp
#include <iostream> #include "add.h" int main() { int x = readNumber(); int y = readNumber(); writeAnswer(x + y); return(0); }io.cpp
int readNumber() { int x; std::cout << "Number: "; std::cin >> x; return x; } void writeAnswer(int x) { std::cout << "Answer: "; std::cout << x; }add.h
#ifndef ADD_H_INCLUDED #define ADD_H_INCLUDED int readNumber(); void writeAnswer(int x); #endif // #ifndef ADD_H_INCLUDED错误出现在 io.cpp 中.确切的错误是:
The error is showing up in io.cpp. The exact errors are:
有人知道为什么会发生这种情况吗?谢谢.
Does anyone have any idea why this may be happening? Thanks.
昨天我用相同数量的文件(2 .cpp 和 1.h)做了一个小项目,我没有在另一个 .cpp 中包含 iostream 标头,但它仍然编译并运行良好.
推荐答案将 #include 添加到 io.cpp 的开头.
add #include <iostream> to the start of io.cpp too.
更多推荐
cout 不是 std 的成员
发布评论