using std::iostream ?

This might be an easy question for most of you I guess.

I want to use "using std::iostream" or similar first in my cpp-files. This is because I have a lot of "cout" and "endl" in my code and it would be dirty code if I have to replace it with "std::cout" and "std::endl". See the attached file for a complete project in VC++ 6.0. But the compiler won't allow this. It won't recognize the cout and endl words, why?

d98rolbSystem Developer Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can use the line
using namespace std;
infront of all occurances of cout and endl to achieve this.
>>It won't recognize the cout and endl words, why?

I assume you are not using the correct namespace - try adding

#include <iostream>
// other STL headers...
using namespace std; // <-- !

Use "using namespace std;" istead. cout and endl are both members of the std namespace.

JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

d98rolbSystem Developer Author Commented:
Hi again, I forgot to say that the VC++ project file can be downloaded on (15 kb)

d98rolbSystem Developer Author Commented:
I don't want to use the simple solution in the start of each file:

using namespace std;

This introduce hard to find errors later in the project because the whole namespace is visible.

Where you would have put using namespace std; you can import only the items you want:

using std::cout;
using std::cin;
using std::endl;


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
>>I don't want to use the simple solution


>>This introduce hard to find errors later

Which errors?
d98rolbSystem Developer Author Commented:
using namespce std;
reveal the whole namespace for the program, proffessional programmers don't use it, and I have now learned why...

>>proffessional programmers don't use it

OK, so you are suggesting that I am acting 'unprofessional'? That's a bummer, gonna have to quit my job...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.