namespace std not found?

Started by
6 comments, last by uber_n00b 20 years ago
OK I really don''t understand this. I open up a program that compiled ok on my computer and simply typed "using namespace std;" and it worked, but I open up a new file and it says "std is not a namespace". Why is this? I cna''t figure it out at all, grr on Visual Studio. Sorry if it seems like I''m spamming.
My fellow Americans I have just signed legislation that outlaws Russia forever. Bombing will commence in five minutes.
Advertisement
have you included any of the C++ standard libraries?


#include <iostream>
#include <string>


etc...

otherwise you''re trying to use a namespace that doesn''t exist as such.

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Ah yes thank you I just found that same exact info on a website. Apparently std is defined within iostream or something? Anyway thanks again.
My fellow Americans I have just signed legislation that outlaws Russia forever. Bombing will commence in five minutes.
Well, a namespace is defined when you put something in it. Various header files in the iostream and related headers, as well as the STL headers, define stuff inside the namespace std.

If you haven''t put anything in std, it doesn''t exist, so you can''t use it.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
BTW don''t use "using namespace std;"
if you you import everything into the global namespace it defeats the purpose of having a namespace in the first place.

If you need something frequently (i.e. a string) use
using std::string;

or if you only need an occasional instance just scope it as you declare it
if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight
also, the ''using namespace'' terms understand scope, so instead of placing them outside of the function at the top of the program below the headers you can place them inside function bodies and even blocks and they wont effect anything outside of that block.
quote:Original post by ChaosEngine
if you you import everything into the global namespace it defeats the purpose of having a namespace in the first place.

Bollocks. Namespaces are for more than preventing name collisions.

Original poster:
Don''t blame your compiler/IDE, that is a surefire indication you are new.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
quote:Original post by antareus
quote:Original post by ChaosEngine
if you you import everything into the global namespace it defeats the purpose of having a namespace in the first place.

Bollocks. Namespaces are for more than preventing name collisions.


yes, they''re also for scoping and code organisation, neither of which is helped by importing an entire namespace.
if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight

This topic is closed to new replies.

Advertisement