开发者

istream and ostream problem - C++ [duplicate]

This question already has answers here: C++ error: ‘string’ has not been declared (3 answers) Closed 10 months ago.开发者_JAVA百科

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


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.


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?)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜