istream 和 ostream 问题 - C++

发布于 2024-10-20 04:55:07 字数 275 浏览 0 评论 0原文

我使用两个编译器 g++ 和 Dev - C++。当我在 Dev-C++ 上编译我的程序时,它编译得很好。但是当我尝试在 g++ 上编译它时,它给了我两个错误:

In file included from a2test.cpp:27:
----.h:25: error: 'ostream' has not been declared
----.h:26: error: 'istream' has not been declared

谁能告诉我我能做什么来解决这个问题。

谢谢

I am using two compilers g++ and Dev - C++. when I compile my program on Dev-C++ it compiles perfectly. but when i try to compile it on g++ it gives me two errors:

In file included from a2test.cpp:27:
----.h:25: error: 'ostream' has not been declared
----.h:26: error: 'istream' has not been declared

Can anyone tell me what can I do to solve this problem.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一念一轮回 2024-10-27 04:55:07

确保包含 fstream。另外,将“std::”放在 ostream 之前或将“using namespace std”放在某处。

如果您发布代码将会有所帮助,因为现在我只是根据常见错误进行猜测。

我猜你忘记包含 fstream 因为不同的编译器可能使用不同的头文件,并且 g++ 可能有一个头文件,

// iostream
#include <fstream>

而 Dev-C++ 可能有

// iostream
// no include for fstream in this file

所以你不小心导入了正确的头文件而不是显式地执行它。

对于头文件,当我忘记是哪个时,我只是使用这个网站。

ostream - C++ Reference

看来您需要包含 ostream 才能获取 ostream。 istream 可能也是同样的情况。

Make sure you include fstream. Also, put "std::" before ostream or put "using namespace std" somewhere.

It would help if you posted the code, as right now I'm just guessing based on common mistakes.

I would guess you forgot to include fstream because different compilers may use different header files and it may be the case that g++ has a header file with

// iostream
#include <fstream>

While Dev-C++ may have

// iostream
// no include for fstream in this file

So you're accidentally importing the correct header file rather than doing it explicitly.

For header files, I just use this site when I forget which one.

ostream - C++ Reference

It seems you need to include ostream to get ostream. Probably the same thing for istream.

浮萍、无处依 2024-10-27 04:55:07

我的通灵调试技巧表明,该问题可能意味着您对 g++ 的调用和 g++ Dev-CPP 使用的是不同版本的 gcc。 Dev-CPP 中包含的(可能是较早的)版本中的标头之一可能#include 一个它不需要的标准 C++ 标头,这将允许非严格意义上的标头 正确编译。

确保您确实已#include、或 code> 或 ——实际上包含这些类型的一些标头。

旁注:请不要使用 Dev-CPP - 该项目几乎已经死了,编辑器犯了很多罪过。而且它无论如何都不是一个好的编辑器。代码怎么样::Blocks 还是 Visual Studio(都是免费的)?)

My psychic debugging skills indicate that the problem likely means that your call to g++ and the g++ Dev-CPP is using are different versions of gcc. One of the headers in the (presumably earlier) version included with Dev-CPP might #include a standard C++ header that it doesn't need to, which would allow headers which aren't strictly correct to compile.

Make sure you've actually #included <iostream>, or <istream> and <ostream>, or <iosfwd> -- some header which actually includes these types for you.

(Side Note: Please don't use Dev-CPP -- the project is pretty much dead, and the editor commits quite a few sins. Plus it isn't a good editor anyway. How about Code::Blocks or Visual Studio (both free) instead?)

灼痛 2024-10-27 04:55:07

不知道这是否有帮助,但首先,你应该记住省略一些其他编译器(MS-C++)使用的“.h”,但不是 ANSI/G++。所以它应该只是

#include <iostream>

其次,不要忘记:

using namespace std;

第三,已经很长一段时间了,但如果我没记错的话,在 g++ 中, istream 和 ostream 函数位于“std”库中..所以你可以这样做:

using std::istream;
//later
istream::iostate state = ...

或者,你可以像这样直接使用它们:

std::istream::iostate state = ...

希望这会给你一些想法。

dont know if this will help, but firstly, yuou should remember to omit the ".h" that some other compilers (MS-C++) use, but not ANSI/G++.so it should be just

#include <iostream>

Secondly, don't forget :

using namespace std;

3rdly, it's been a long time, but if I remember correctly, in g++, th istream and ostream functions are in the "std" library .. so you can do something like this :

using std::istream;
//later
istream::iostate state = ...

or alternatively, you can use them directly like this :

std::istream::iostate state = ...

Hopefully that'll give you some ideas.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文