Thread: using namespace std;

  1. #1
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Question using namespace std;

    is there a header file for namespace or is it just my compiler?

  2. #2
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    namespace is a keyword, which means it is your compiler.

    Are you sure you are using a C++ compiler and not a C compiler?

  3. #3
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    ...

    its called borland c++

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793

    Re: ...

    Originally posted by drdroid
    its called borland c++
    If you have an old version then namspaces will probably not work properly......but as you like borland, you can download the newest version for free from their site and that should support them fine

  5. #5
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Never use: using namespace std in your programs.

  6. #6
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    yeah, I prefer not using it

  7. #7
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    You probably perfer not bathing as well.

  8. #8
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    Originally posted by Troll_King
    You probably perfer not bathing as well.
    Damn straight

  9. #9
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    Fordy's suggestion is a good one. Borland 4.0 supports the standard namespace and the download is version 5.5, so you're all set on that issue.

    Now, where Troll_King's admonition is concerned, I would offer this:
    It is generally in poor taste to dump every name from a namespace into the global namespace.

    -Bjarne Stroustrup
    I don't know whether Troll_King is backing Mr. Stroustrup up here, or vice-versa, but the message is clear enough.

    Some might offer, with some validity, that, for smaller applications, 'using namespace std;' isn't so big an issue. Perhaps, but neither is it difficult to avoid using it in small applications, either.
    Code:
    #include <string>
    #include <iostream>
    #include <cstdlib>  // for system("PAUSE")
    
    using std::cout;
    using std::cin;
    using std::endl;
    using std::string;
    
    int main(void)
    {
    string name;
    cout << "Type in your name -> ";
    getline(cin, name);        // does not stop read at 'whitespace' chars
    
    cout << "\nHello, " << name << "!" << endl << endl;
    
    system("PAUSE");
    return 0;
    }
    A trivial example, of course, but illustrates how to avoid extra typing if you don't have the inclination.

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

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, 03: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, 08:39 AM
  4. need ; before using namespace std
    By wwfarch in forum C++ Programming
    Replies: 7
    Last Post: 05-11-2004, 10:42 PM
  5. Site tutorials
    By Aalmaron in forum C++ Programming
    Replies: 20
    Last Post: 01-06-2004, 02:38 PM