A fourth noobie question - namespace std?

This is a discussion on A fourth noobie question - namespace std? within the C++ Programming forums, part of the General Programming Boards category; Ok, i'l explain. A namespace is like a word before every function in it to avoid that it has the ...

  1. #16
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Ok, i'l explain.

    A namespace is like a word before every function in it to avoid
    that it has the same name as another function.

    demonstartion, whe want 2 integers, and whe want both of
    them to be called name,but thats not possible so whe use a
    namespace.

    Code:
    #include <iostream>
    
    using namespace std;
    
    
    namespace tom
    {
    int age=11;
    }
    
    namespace pete
    {
    int age=14;
    }
    
    
    int main()
    {
    
    cout << tom::age; // Print the age int stored in the namespace tom
    
    cout << pete::age; // Print the age int stored in the namespace pete
    
    
    return 0;
    }
    Easy as that, of course this long from everything but this are just
    the fundementals.

    As for the 'using namespace std;' , that just means you dont have to put 'std::' before everything you want to use for that namespace.

  2. #17
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167
    so since i cant use namespace std; where would i put std in the above program?

  3. #18
    Registered User
    Join Date
    Dec 2002
    Posts
    103

    Dump It :)

    Originally posted by Noobie
    so since i cant use namespace std; where would i put std in the above program?
    Include all your headerfules with ".h"
    and just don't add using namespace std

    in that case you can use it without prefixing it with std
    for example
    Code:
    #include <iostream.h>
    #include <string.h>
    
    int main()
    {
         cout << "I have not used std anywhere and it still works" << endl;
         cout << "Its outdated ofcourse " << endl;
          return 0;
    }
    Have a wonderful day.... and keep smiling... you look terrific that way
    signing off...
    shiv... as i know him

  4. #19
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167
    The above worked

  5. #20
    Registered User
    Join Date
    Dec 2002
    Posts
    103

    I am exhausted :)

    Originally posted by Noobie
    The above worked
    Atlast...... It did Wooofffff!!!!!!!!!!! I need a breather
    Last edited by shiv_tech_quest; 01-21-2003 at 08:33 AM.
    Have a wonderful day.... and keep smiling... you look terrific that way
    signing off...
    shiv... as i know him

  6. #21
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    great to hear it worked. my previous post was so you are at least exposed to it. just remember, that iostream.h is nonstandard and newer compilers will give you warnings for it.

  7. #22
    Registered User
    Join Date
    Aug 2005
    Posts
    16
    are you using a c++ compiler or a vc++ compiler?

  8. #23
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Quote Originally Posted by fingerlickin
    are you using a c++ compiler or a vc++ compiler?
    You do realize this thread is 2 years old, don't you?

  9. #24
    Registered User
    Join Date
    Aug 2005
    Posts
    128
    Oh, MS VC++ 6.0

  10. #25
    Registered User
    Join Date
    Aug 2005
    Posts
    128
    oops, wrong thread...funny thing answer is related.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using namespace std error
    By Kayoss in forum C++ Programming
    Replies: 0
    Last Post: 04-26-2006, 01:56 PM
  2. #using namespace std;
    By mrafcho001 in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2005, 04:47 PM
  3. need ; before using namespace std
    By wwfarch in forum C++ Programming
    Replies: 7
    Last Post: 05-11-2004, 10:42 PM
  4. using namespace std; question.
    By fuh in forum C++ Programming
    Replies: 2
    Last Post: 12-30-2002, 03:39 PM
  5. namespace question
    By Sebastiani in forum C++ Programming
    Replies: 2
    Last Post: 04-20-2002, 01:16 PM

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