Need help with a newbie project!

This is a discussion on Need help with a newbie project! within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by Elysia using namespace std; which essentially tells the compiler: if you can't find this symbol in the ...

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,662
    Quote Originally Posted by Elysia
    using namespace std;

    which essentially tells the compiler: if you can't find this symbol in the global namespace (ie no namespace at all), then look in the std namespace.
    So when you type cout, the compiler searches for ::cout (global namespace), then std::cout.
    Not quite: it depends on where the using directive is placed. Furthermore, I do not think the "the compiler searches for ::cout (global namespace), then std::cout". Rather, if ::cout also existed, there would be a name collision resulting in an ambiguity that can only be resolved by either removing the using directive or fully qualifying the names.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    Eep
    Eep is offline
    Registered User
    Join Date
    Jun 2012
    Posts
    6
    Wow, I see. That makes sense. Thanks for the explanation.

    Does not including something like
    Code:
    using namespace std;
    initially have some kind of advantage? (Something beyond me maybe? Like memory management or something.....)

  3. #18
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,555
    It reduces the risks for namespace collision. That is, ambiguity where the compiler cannot decide upon if you meant, say, ::foo, or bar::foo.
    For example, use the "using namespace std" and then declare a min or max function that takes two ints and returns an int. Then call that. It demonstrates very well the disadvantages of namespace directives.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,662
    Quote Originally Posted by Eep
    Does not including something like
    Code:
    using namespace std;
    initially have some kind of advantage?
    Yes, the advantage is that you don't have to qualify names in the std namespace, which can make code both easier to read and write when many names in the std namespace are used. However, if you are using names that are also in the std namespace and/or have other using directives, then your code could end up easier to write but harder to read because of the possibility of name collision.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Classes Project (Not class project)
    By adam.morin in forum C++ Programming
    Replies: 3
    Last Post: 02-28-2011, 12:48 AM
  2. Paid project - The Free Marketing Project
    By sharefree in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 10-27-2010, 02:15 PM
  3. Project Euler Solved but want help improving the code Newbie
    By whiterebbit in forum C++ Programming
    Replies: 4
    Last Post: 12-09-2008, 06:00 AM
  4. newbie q: include files outside the project dir?
    By BrianK in forum Windows Programming
    Replies: 3
    Last Post: 06-29-2004, 03:45 PM
  5. your 11th & 12th grade c++ project or similar project
    By sleepyheadtony in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 01-13-2002, 04:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21