Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


using std::iostream ?

Posted on 2003-12-09
Medium Priority
Last Modified: 2013-12-14
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?

Question by:d98rolb
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 13

Expert Comment

ID: 9904584
You can use the line
using namespace std;
infront of all occurances of cout and endl to achieve this.
LVL 86

Expert Comment

ID: 9904586
>>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; // <-- !

Expert Comment

ID: 9904594

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 9904649
Hi again, I forgot to say that the VC++ project file can be downloaded on (15 kb)


Author Comment

ID: 9904685
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.
LVL 11

Accepted Solution

bcladd earned 150 total points
ID: 9904737

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;

LVL 86

Expert Comment

ID: 9904767
>>I don't want to use the simple solution


>>This introduce hard to find errors later

Which errors?

Author Comment

ID: 9905572
using namespce std;
reveal the whole namespace for the program, proffessional programmers don't use it, and I have now learned why...

LVL 86

Expert Comment

ID: 9905585
>>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...

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question