943,735 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1453
  • C++ RSS
Sep 18th, 2006
1

problem with headers and streams

Expand Post »
I ve read that iostream is a derived class of fstream ,so including the "fstream" header is all sufficient to perform console i/p and o/p(ie cin and cout) .this worked fine as long as I used Turbo C++ compiler but now I ve switched to Bloodshed Dev C++ compiler and it gives an error that cin is not recognized....it works fine only if I include both "iostream" and "fstream" in my program ....please help
Last edited by sugantha; Sep 18th, 2006 at 8:22 pm.
Similar Threads
Reputation Points: 22
Solved Threads: 0
Newbie Poster
sugantha is offline Offline
17 posts
since Sep 2006
Sep 18th, 2006
1

Re: problem with headers and streams

Some C++ compilers do not require IO imports to include cin/cout. The same is true with some C compilers and printf etc.
Reputation Points: 20
Solved Threads: 5
Junior Poster
alpha_foobar is offline Offline
182 posts
since May 2005
Sep 19th, 2006
2

Re: problem with headers and streams

Well, according to this:
http://www.cppreference.com/cppio/index.html
cin, cout are defined in iostream.
And this will also help ypu understand what is going on.
http://www.cplusplus.com/ref/iostream/

I hope it helps!
Reputation Points: 55
Solved Threads: 6
Junior Poster
Micko is offline Offline
148 posts
since Aug 2005
Sep 19th, 2006
1

Re: problem with headers and streams

I think you did'nt read my question clearly...I asked if iostream is a derived class of fstream then it has to inherit all its properties...so cin and cout SHOULD work fine....it does so with the Borland compiler but not with Dec-C++ compiler ...why??
Reputation Points: 22
Solved Threads: 0
Newbie Poster
sugantha is offline Offline
17 posts
since Sep 2006
Sep 19th, 2006
1

Re: problem with headers and streams

Does your borland compiler also work if you include iostream (only) to get cin and cout ?
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Sep 19th, 2006
1

Re: problem with headers and streams

yes...it works fine
Reputation Points: 22
Solved Threads: 0
Newbie Poster
sugantha is offline Offline
17 posts
since Sep 2006
Sep 19th, 2006
1

Re: problem with headers and streams

OK, so use that then from now on and don't assume that a particular implementation choice about the inheritance of various objects will be true in other implementations.

My guess is you "got away with" using fstream for cout previously, but this "trick" no longer works on your new compiler.

Which is why you should learn from high quality sources of documentation (like the C++ standard), rather than relying on your reverse engineered observations of a particularly old compiler.

Using multiple compilers even when you don't have to is also a good way of flushing out any assumptions you might be making.

I'm presently using 3 different compilers with pretty strict error checking. It's been a long while since I last used just one compiler for a whole project.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: c++ white space question?
Next Thread in C++ Forum Timeline: new to C++ calculator problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC