Thread: what does this actually do??

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    34

    what does this actually do??

    using namespace std;

    I have no idea what the importance of the above is.

    Thanks

  2. #2
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    don't know for sure either... but someone [i think davidp] told me that it was for correct function recognition when functions have preceding underscores...
    hasafraggin shizigishin oppashigger...

  3. #3
    Registered User The15th's Avatar
    Join Date
    Aug 2001
    Posts
    125
    the std namespace is the namespace which the entire Standard c++ libarary is declared. So when you use namespace std you simplify access to the standard library. I also herd it deals with clashes between old and new header files.
    arrh, i got nothing good to say.
    http://www.praxis1.vic.edu.au/home/dcola/

  4. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    A namespace is a piece of code that is encapsulated within a pair of brackets, just like any other class.

    Example:

    namespace a
    {
    int AAA;
    };

    namespace b
    {
    int BFunc( int x )
    {
    return x;
    }
    }

    int main()
    {
    AAA = 5; // error: unknown identifier AAA
    a::AAA = 5; // ok
    BFunc( AAA ); // error: unknown identifiers: AAA and BFunc
    b::BFunc( a::AAA ); // ok

    return 0;
    }

    The using directive means you try to use this prefix automatically:

    using namespace a;

    int main()
    {
    AAA = 5; // ok, a:: added automatically
    a::AAA = 5; // ok
    BFunc( AAA ); // error: unknown identifier BFunc
    b::BFunc( a::AAA ); // ok

    return 0;
    }

    All functions in the C++ headers belong to namespace std.
    So you can either use this in front of all your functions, or
    set it once.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed