namespace std not found?
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.
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
#include <iostream>
#include <string>
etc...
otherwise you''re trying to use a namespace that doesn''t exist as such.
hth
Jack
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.
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.
If you haven''t put anything in std, it doesn''t exist, so you can''t use it.
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 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
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.
quote:Original post by antareusquote: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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement