Thread: A fourth noobie question - namespace std?

  1. #1
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167

    A fourth noobie question - namespace std?

    using namespace std;

    The tutorials I get sent to often have this in them, but when i try to use this my compiler says, "Namespace name expected" ?

  2. #2
    Registered User
    Join Date
    Dec 2002
    Posts
    103

    You might be using an outdated compiler

    #include <iostream> // does not work
    using namespace std; // does not work

    try
    #include <iostream.h> // this is the old style. So could solve ur problem
    Have a wonderful day.... and keep smiling... you look terrific that way
    signing off...
    shiv... as i know him

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    http://cboard.cprogramming.com/showt...sing+namespace

    edit: post some code, it should work. also what compiler?

  4. #4
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167
    Code:
    #include <iostream.h> 
    using namespace std; 
    int main()
    {
         cout << "Hello World\n";
    }

  5. #5
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167
    Borland C++ 5.02

  6. #6
    Registered User
    Join Date
    Dec 2002
    Posts
    103

    Do any one

    Either say
    Code:
    #include <iostream.h>
    
    int main()
    {
         cout << "Hello World" << endl;
         return 0;
    }
    or

    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
         cout << "Hello World" << endl;
         return 0;
    }
    or even better

    Code:
    #include <iostream>
    int main()
    {
         std::cout << "Hello World" << std::endl;
         return 0;
    }
    Note: One of the members provided a link, please visit that. It will explain a lot of details about namespaces
    Have a wonderful day.... and keep smiling... you look terrific that way
    signing off...
    shiv... as i know him

  7. #7
    efae
    Guest
    Try #include <iostream>

  8. #8
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167
    This does not work either:

    I went to the link and I still don't see whats wrong

    Code:
    #include <iostream> 
    using namespace std; 
    int main()
    {
         cout << "Hello World\n";
    }

  9. #9
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167
    Nor does this work as std is not a class or namespace and there is a statement missing


    Code:
    #include <iostream>
    int main()
    {
         std::cout << "Hello World" << std::endl;
         return 0;
    }

  10. #10
    Registered User
    Join Date
    Dec 2002
    Posts
    103

    Try the first form out of the three

    Originally posted by Noobie
    Nor does this work as std is not a class or namespace and there is a statement missing


    Code:
    #include <iostream>
    int main()
    {
         std::cout << "Hello World" << std::endl;
         return 0;
    }
    I have posted 3 forms of the program, you have tried only the 2nd and the 3rd. Try the first form. It must work

    Note: I don't use namespace at all in the first form
    Have a wonderful day.... and keep smiling... you look terrific that way
    signing off...
    shiv... as i know him

  11. #11
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167
    but why? am i not supposed to ever use namespace? why is it in all the tutorials? Some of them call for


    #include "string6.h" what is that? it doesnt work either

  12. #12
    Registered User
    Join Date
    Dec 2002
    Posts
    103

    Well you are not using the right compiler

    Originally posted by Noobie
    but why? am i not supposed to ever use namespace? why is it in all the tutorials? Some of them call for


    #include "string6.h" what is that? it doesnt work either
    Chill out

    The compiler that you are using might have been developed when namespaces were not existing as part of C++. So your compiler does not have most of the recently added features / libraries of C++. So just change to the latest compilers and your problem would be solved.

    w.r.t namespaces

    When you say #include<iostream.h>
    everything is loaded into the global namespace at one shot

    If you had split your contents into multiple sections (lets say std1, std2, std3, std4) and didn't want everything to be stuffed in the global namespace, then you could say

    using namespace std1; and that would load only what is there in std1 in the global space and will not load std2 / 3/ 4 in the global namespace.

    Having said that std1/2/3/4 was just to help you understand. There are no such namespaces available.. unless you create any with those names
    Have a wonderful day.... and keep smiling... you look terrific that way
    signing off...
    shiv... as i know him

  13. #13
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167
    so i can only do tutorials written last year??

  14. #14
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    the above posted should work. that's weird. the "string6.h" is a different header file, most likely for a class.

    for the "but why? am i not supposed to ever use namespace?", you could do this either of three ways...

    using namespace std;
    OR
    using std::cout;
    using std::endl;
    //continue with more if necessary
    OR
    std::cout << std::endl;
    //like in previous examples

  15. #15
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167
    using std::cout;
    using std::endl;
    //continue with more if necessary
    OR
    std::cout << std::endl;

    uh... :< it seems pretty difficult to explain that Im a noobie asking for help on a HelloWorld compilation-i dont know what std is and I dont know what all that code u are telling me I could use is and I can't read some tutorial to find out when the tutorials dont even work

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, 05: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, 04:39 PM
  5. namespace question
    By Sebastiani in forum C++ Programming
    Replies: 2
    Last Post: 04-20-2002, 01:16 PM