Thread: using namespace: definition?

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    12

    using namespace: definition?

    I haven't done C++ in like... 1 or 2+ years...

    and I redownload some compiler and decide to start agian.

    and i look at some tutorial to refresh my memory...

    Code:
    using namespace std;
    wtf?!



    And i know theres other like
    Code:
    using std:name;
    I just would like some simple explanation of what this does.. and what it can help. Just, so I know why i put it there, and so i can use for future reference. Thank you!

  2. #2
    I'm less than sure.... abyssphobia's Avatar
    Join Date
    Aug 2004
    Posts
    112
    well using namespace std; is for using the standar headers, and earn you to have to use in each sentence
    Code:
    #include<iostream>
    int main{
    int whatever, i;
    std::cout<<"give blah blah ";
    std::cin>>whatever;
    return 0;
    }
    so you can do something like that has the same result but makes it a little confusing when the program comes long, but yeah you can impress your friends no programmer in C++ using that,lol.
    or
    Code:
    #include<iostream>
    using namespace std;
    int main{
    int whatever, i;
    cout<<"give blah blah ";
    cin>>whatever;
    return 0;
    }
    and its better then (to me) beside to use the header with .h, well I read that the C++ handle the .h because of C.
    hope this help
    Last edited by abyssphobia; 10-10-2004 at 10:55 PM.
    Have I crossed the line?

  3. #3
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    To clear up what was said before all of the standard functions and other things are in the namespace std. This is to avoid namespace collisons. Basically if you want to use any standard stuff like cout,cin,fstreams,... you have to either std::whatever in front of every time you use it. Or put using std::whatever gloabaly or you could go the easy using namespace std as a global namespace
    Woop?

  4. #4
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715
    Names in C++ can refer to variables, functions, structures, enumerations, classes, and class and structure members. When programming projects grow large, the potential for name conflicts increases. When you use class libraries from more than one source, you can get name conflicts. For example, two libraries might both define classes named List, Tree, and Node, but in incompatible ways. You might want the List class from one library and the Tree from the other, and each might expect its own version of Node. Such conflicts are termed namespace problems.

    The C++ Standard provides namespace facilities to provide greater control over the scope of names. It has taken a while for compilers to incorporate namespaces, but, by now, support has become common.

    example:
    Code:
    namespace Jack {
        double pail;
        void fetch();
        int pal;
        struct Well { ... };
    }
    Placing a using-directive at the global level makes the namespace names available globally. You've seen this in action many a time:

    Code:
    #include <iostream>    // places names in namespace std
    using namespace std;   // make names available globally
    Placing a using-directive in a particular function makes the names available just in that function.
    Code:
    int vorn(int m)
    {
        using namespace jack; // make names available in vorn()
    ...
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  3. Duplicate definition.
    By Exit in forum C++ Programming
    Replies: 8
    Last Post: 02-26-2008, 02:45 PM
  4. A stupid question...probably
    By Phoenix_Rebirth in forum C++ Programming
    Replies: 14
    Last Post: 09-26-2007, 04:53 PM
  5. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM