Solved

using std::iostream ?

Posted on 2003-12-09
9
2,585 Views
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?

/Roland
0
Comment
Question by:d98rolb
[X]
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
9 Comments
 
LVL 13

Expert Comment

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

Expert Comment

by:jkr
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; // <-- !
0
 
LVL 1

Expert Comment

by:Tobber
ID: 9904594
Hi.

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

/T
0
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

by:d98rolb
ID: 9904649
Hi again, I forgot to say that the VC++ project file can be downloaded on http://hem.passagen.se/d98rolb3/uploads/Lista.zip (15 kb)

0
 

Author Comment

by:d98rolb
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.
0
 
LVL 11

Accepted Solution

by:
bcladd earned 50 total points
ID: 9904737
Okay:

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;

-bcl
0
 
LVL 86

Expert Comment

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

Hum.

>>This introduce hard to find errors later

Which errors?
0
 

Author Comment

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


0
 
LVL 86

Expert Comment

by:jkr
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...
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

626 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