problem with headers and streams

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2006
Posts: 17
Reputation: sugantha is an unknown quantity at this point 
Solved Threads: 0
sugantha's Avatar
sugantha sugantha is offline Offline
Newbie Poster

problem with headers and streams

 
1
  #1
Sep 18th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 182
Reputation: alpha_foobar is an unknown quantity at this point 
Solved Threads: 3
alpha_foobar's Avatar
alpha_foobar alpha_foobar is offline Offline
Junior Poster

Re: problem with headers and streams

 
1
  #2
Sep 18th, 2006
Some C++ compilers do not require IO imports to include cin/cout. The same is true with some C compilers and printf etc.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 148
Reputation: Micko is on a distinguished road 
Solved Threads: 6
Micko Micko is offline Offline
Junior Poster

Re: problem with headers and streams

 
2
  #3
Sep 19th, 2006
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!
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 17
Reputation: sugantha is an unknown quantity at this point 
Solved Threads: 0
sugantha's Avatar
sugantha sugantha is offline Offline
Newbie Poster

Re: problem with headers and streams

 
1
  #4
Sep 19th, 2006
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??
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: problem with headers and streams

 
1
  #5
Sep 19th, 2006
Does your borland compiler also work if you include iostream (only) to get cin and cout ?
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 17
Reputation: sugantha is an unknown quantity at this point 
Solved Threads: 0
sugantha's Avatar
sugantha sugantha is offline Offline
Newbie Poster

Re: problem with headers and streams

 
1
  #6
Sep 19th, 2006
yes...it works fine
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: problem with headers and streams

 
1
  #7
Sep 19th, 2006
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC