Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

uber_n00b

namespace std not found?

This topic is 5331 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!