istream 和 ostream 问题 - C++
我使用两个编译器 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
确保包含 fstream。另外,将“std::”放在 ostream 之前或将“using namespace std”放在某处。
如果您发布代码将会有所帮助,因为现在我只是根据常见错误进行猜测。
我猜你忘记包含 fstream 因为不同的编译器可能使用不同的头文件,并且 g++ 可能有一个头文件,
而 Dev-C++ 可能有
所以你不小心导入了正确的头文件而不是显式地执行它。
对于头文件,当我忘记是哪个时,我只是使用这个网站。
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
While Dev-C++ may have
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.
我的通灵调试技巧表明,该问题可能意味着您对 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
#include
d<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?)
不知道这是否有帮助,但首先,你应该记住省略一些其他编译器(MS-C++)使用的“.h”,但不是 ANSI/G++。所以它应该只是
其次,不要忘记:
第三,已经很长一段时间了,但如果我没记错的话,在 g++ 中, istream 和 ostream 函数位于“std”库中..所以你可以这样做:
或者,你可以像这样直接使用它们:
希望这会给你一些想法。
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
Secondly, don't forget :
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 :
or alternatively, you can use them directly like this :
Hopefully that'll give you some ideas.