using namespace std, What does it do?

This is a discussion on using namespace std, What does it do? within the C++ Programming forums, part of the General Programming Boards category; What does "using namespace std" do? I am new to C++ and have seen it in a lot of source ...

  1. #1
    Ben K.
    Guest

    Question using namespace std, What does it do?

    What does "using namespace std" do? I am new to C++ and have seen it in a lot of source code. Just wondering, Thanks.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    156
    The c++ Standard Library is defined within the "std" namespace. A namespace is a unique declarative region that attaches an additional identifier to any names declared inside it.

    namespace foobar
    {
    int i;
    int j;
    }

    These ints names won't collide because they are foobar::i and foo::i, respectively.

    namespace foo
    {
    int i;
    int j;
    }

    This allows reuse of names and prevents name collisions, which can be a problem with very large projects. In order to get access to names within the "std" namespace (actually any namespce) you either need to use scope resolution operator for the namespace( std::cout ) or access the entire namespace by using the "using namespace std;". The second method allows the use of names within the namespace without using the scope resolution operator such as "cout" not std::.

    Now that I've given a long answer to a short question, the using namespace std allows access to the C++ Standard Library without using the scope resolution operator, std::.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why std:: and not using namespace std?
    By swappo in forum C++ Programming
    Replies: 4
    Last Post: 07-03-2009, 04:10 PM
  2. std:: or namespace std
    By C-+ in forum C++ Programming
    Replies: 16
    Last Post: 12-04-2007, 12:30 PM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 09:39 AM
  4. need ; before using namespace std
    By wwfarch in forum C++ Programming
    Replies: 7
    Last Post: 05-11-2004, 11:42 PM
  5. Site tutorials
    By Aalmaron in forum C++ Programming
    Replies: 20
    Last Post: 01-06-2004, 02:38 PM

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