namespace

This is a discussion on namespace within the C++ Programming forums, part of the General Programming Boards category; Besides cout, cin, and endl, what exactly does using namespace std; include?...

  1. #1
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357

    namespace

    Besides cout, cin, and endl, what exactly does using namespace std; include?

  2. #2
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    It's a way of compartmentalising declared variables and type definitions.

    When you link to multiple libraries, people are bound to re-use names. Namespaces help to avoid this.

    What would you call a dictionary class type? Dictionary perhaps, or may Dict? If you had to link to two libraries where the same name was used twice it would cause a problem. However, with namespaces you can refer to them as, for example:

    Acme:ict

    and

    SuperSoft:ict
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  3. #3
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357
    You explained what it does, but what does it include?

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    It includes a lot, a lot to list.

    but other examples.

    ifstream
    ofstream
    vector
    string
    iomanip stuff

    etc. etc.

  5. #5
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    Ooops! So I did. Must take time to read questions more thoroughly.

    Try this:

    http://www.cs.rpi.edu/projects/STL/htdocs/stl.html
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  6. #6
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357


    What does the standard template library have to do with this?



    Anyway, for example: if you only use cout, cin and endl in your program, you can use this...

    using std::cout;
    using std::cin;
    using std::endl;

    ...instead of using namespace std;

    I just want to know what all of the - how should I say this? - std's.

    I know a few more...

    using std::ios;
    using std::fixed;
    using std::showpoint;

  7. #7
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Every standard header file that doesn't end in .h is found in the std namespace. However, to have access to the specific part, you have to include the correct header.

  8. #8
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357
    >>Every standard header file that doesn't end in .h is found in the std namespace. However, to have access to the specific part, you have to include the correct header.


    I'm sure there are too many header files for you to list here, so can you provide a link or anything to where I may find a listing of all of them? Please

  9. #9
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    It's been a while since I've been out here, volk, but a reasonably good response to your question can be found in Scott Meyers' book, Effective C++.

    Unless you're writing a paper, or something of the sort, a good compiler will be happy to tell you when you've "messed up", i.e. included a command not included in namespace std.

    That being said, there are a myriad of threads available suggesting against the use of "using namespace std".

    You've cited examples of avoiding such use, yourself. From a "maintenance" standpoint...hmmmm. Might be some "backtracking" involved.

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  10. #10
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    using std::cout;
    using std::cin;
    using std::endl;

    ...instead of using namespace std;

    Yes, you can do that. I know some people advocate doing it the first way, but why would anyone want to do all that typing? The second method only requires you to type one line.

  11. #11
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Originally posted by 7stud
    using std::cout;
    using std::cin;
    using std::endl;

    ...instead of using namespace std;

    Yes, you can do that. I know some people advocate doing it the first way, but why would anyone want to do all that typing? The second method only requires you to type one line.
    it's a preference of style. some people prefer not to pollute the global space.

  12. #12
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Basically, when you say using namespace std;, if anything has a variable name that you are using, the compiler chokes because of multiple declarations.

    As for a list, www.dinkumware.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. extern namespace?
    By Brafil in forum C++ Programming
    Replies: 2
    Last Post: 01-10-2009, 07:06 AM
  2. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  5. data validation & namespace
    By tiange in forum C++ Programming
    Replies: 4
    Last Post: 07-05-2005, 02:45 AM

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