cout 不是 std 的成员

编程入门 行业动态 更新时间:2024-10-27 06:21:31
本文介绍了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.

这是我的文件:

ma​​in.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 的成员

本文发布于:2023-11-10 03:17:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574208.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:成员   cout   std

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!