Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

iostream.h problem

Status
Not open for further replies.

marinepcsafety

Technical User
Oct 29, 2006
1
US
Hi the iostream.h command always fails to compile giving me the error c1083 file not found or no such director.When i try to build the file iostream i get 103 errors, i had a c++ professer look over it and he said it was fine but he does not know why iostream.h doesnt work.In borland c++ iostream.h does work fine but i dont have borland , my school does. Any help would be great.THIS IS MICROSOFT VISUAL 2005 EXPRESS EDTION, thanks
 
iostream.h shouldn't be used anymore in C++ programs. You should include <iostream> instead.
 
iostream.h was a pre-standard header. It was replaced by iostream about 8 years ago in the C++ standard. Many modern compilers no longer support the old version.

Unfortunately, if your professor doesn't know this, there is a good chance you are learning bad C++ habits. Don't be surprised when you find out that other stuff you've learned is outdated as well.

You'll want to search for the difference between <iostream.h> and <iostream> so you can understand how to update your code.
 
If you're using iostream, don't forget to add

using namespace std;

after all your headers.
 
Instead of doing that, it is really better to just prefix all standard names with std::, in my opinion. Why defeat the purpose of the namespace, and why get into a habit that you will want to break when you move on to larger projects?

And I have seen beginner programs that have failed because of the use of the using directive, so it is possible that it has an effect.
 
I used to have the same opinion about namespaces. Then I starting using only the names I needed:
Code:
#include <iostream>

using std::cout;
using std::endl;
...

and now I just use the whole namespace and avoid declaring anything with the same name as what's in the std namespace.

However, you should NEVER put a using declaration in a header file. It's very rude to the people including your header and could cause problems for them...
 
cpjust said:
and now I just use the whole namespace and avoid declaring anything with the same name as what's in the std namespace.
Again, this is fine for small programs, but when you start using other people's code you have no control over what names they use.

And while putting a using directive or declaration in a header is more dangerous than doing it in a cpp file, if you are writing code that is meant to be contained in your application anyway there isn't that big of a difference.
 
I think readability is a pretty important part of writing good code, and putting std:: infront of all your STL types & functions just makes the code a lot longer and harder to read.
99.9% of the time, I've never run into any namespace crashes. When I do get an "ambiguous name..." compile error, then I'll fully qualify the name.
 
Sometimes you don't get a compile error, sometimes you simply get incorrect behavior that is difficult to detect.

In addition, use of std:: makes code easier to read by identifying which names are from standard libraries and differentiating them from your own names. Many standard library names are simple and looking at code with out the namespace prefix makes it difficult to see the difference between a library name and a local name.

Like I said, use of the using directive is in almost all cases fine for small programs. It is just not a good habit to get into if you ever have to work on something more.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top