Thread: Need help with a newbie project!

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

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, 01: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, 07: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, 05:14 PM