Advertisement

using namespace std

Started by September 05, 2002 03:18 PM
5 comments, last by Zorbfish 22 years, 2 months ago
when I put this at the top of my code in MVC++ 6.0 I get an error saying there is no such namespace. I know of (which I use). Are these two similar and which is the most current?
Not sure what you are comparing std to, but are you using header files with .h at the end or without? Most of the time you will use header files without .h as that is the new standard.
-------------------------GBGames' Blog: An Indie Game Developer's Somewhat Interesting ThoughtsStaff Reviewer for Game Tunnel
Advertisement
stdlib.h is an old C header file. Namespaces are a C++ concept which do not exist in C, so the contents of C headers are in the global namespace. Newer C++ specific header files have their contents within "namespace std", and the compiler needs to be told which namespace to use. So, the rule is this: if you include a C++ header, which you can identify because it has no ".h" at the end of its name, then you must specify namespace std; if you use a C header, you do not need to specify any namespace. Lastly, if you have not #include''d a C++ header which declares namespace std, then any attempt to reference namespace std will fail. That''s the problem you''re getting.
Ya, I know all that but for instance if I type:

#include <iostream>

using namespace std;

int main(){
cout >> "Hello";
return 1;
}

I recieve an error from my compiler saying that there is no such namespace.
Ok i put yours in and it returned an error, then i put my own in and it compiled fine :/.

This is mine :

#include <iostream>

using namespace std;

main()
{
cout << "Hi" << endl;
return 0;
}
quote: Original post by Zorbfish

cout >> "Hello";



dunno about the namespace problem but you seem to be a bit confused, you mean to write cout << "hello";

edit: spelling


[edited by - necromancer_df on September 5, 2002 8:15:12 PM]
Advertisement
look inside your iostream header file. See if there is a namespace.. STL header files should have the namespace unless its not a standard version.

This topic is closed to new replies.

Advertisement