473,396 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Namespace std

60
Hi Guys,

Is a reason why people sometimes don't use namespace std as it is i.e
using namespace std;

instead they opt for something like:
using std::cout;
using std::cerr;
using std::endl;
using std::showbase;
using std::noshowbase;
using std::hex;
using std::dec;

Is any difference?
Jul 17 '07 #1
2 1940
Meetee
931 Expert Mod 512MB
Hi Guys,

Is a reason why people sometimes don't use namespace std as it is i.e
using namespace std;

instead they opt for something like:
using std::cout;
using std::cerr;
using std::endl;
using std::showbase;
using std::noshowbase;
using std::hex;
using std::dec;

Is any difference?
As far as my knowledge is concerned, instead of using the whole std library, using std::xyz; means you need only that specific part of std library.

Regards
Jul 17 '07 #2
Darryl
86
It's because they don't want to pollute the global namespace. Namespaces are there to help prevent collision of identifiers from different libraries/code etc. Common names like count, max, min are used in a lot of different code. Those 3 are also part of the std:: namespace. If your program uses count for example, then you've got an error if you use "using namespace std;"

using namespace was really only included so legacy code didn't break and people like Stroustrup discourages its use in new code.

Slightly better, you can just pull in certain identifiers from a namespace instead of all of them, for example using std::cout, if you plan on doing a lot of output, but really this is also discouraged.
Jul 17 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: John L. Clark | last post by:
I am curious as to the rationale, and effect, of having default namespaces not applying (directly) to attributes (see http://www.w3.org/TR/REC-xml-names/#defaulting). Given an attribute without a...
3
by: Mike Dickens | last post by:
hi, i'm sure this has come up before but havn't managed to find an answer. if i have the following xslt <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet method="xml" version="1.0"...
8
by: Petter Reinholdtsen | last post by:
I ran into a problem on HP-UX 11.00 the other day, where it refused to compile a program using 'using namespace std;' at the top. The reason seem to be that the compiler refuses to accept 'using...
7
by: Kevin Newman | last post by:
I've been toying with a namespace manager, and wanted to get some input. So what do you think? if (typeof com == 'undefined') var com = {}; if (!com.unFocus) com.unFocus = {}; ...
14
by: Tiraman | last post by:
Hi , I would like to use nested namespace . I have 3 namespace as dll's : Namespace A Namespace B Namespace C And i want to have some namespace that contain them all , some thing like
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.