Hi. What's the features for "using namespace std;" in VC ? Thing it should be used whenever including <fstream> , but I really dunno...What does it do? What it's responsible for?
Rather than specifying "using namespace std;" you may be better off specifying "std::vector", "std::cout", "std::string", etc.
This whole subject has been a cause for argument amongst programmers for a while. Using the latter involves more typing but avoids ambiguities and confusion in the code.
You should use std with any of the STL containers, algorithms, etc.
programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
C++ hasn't always had namespaces; not named ones, anyway. There used to just be global stuff. i.e. all the stuff was scattered out on the floor for anyone to use. Messy, messy.
Then, they decided to let programmers define namespaces. This lets us take all our stuff, clean it off the floor, and put it into nice little packages. We can use what we want from each package without leaving everything else strewn all over the place. Standard C++'s stuff is all in one box, and it's called "std." It has a bunch of cool stuff in it... vector, string, ostream, pair, map, binary_function, istreambuf_iterator... stuff you use every day.
Now, think of "using namespace std;" as taking that box and dumping it all out on the floor. You get all that stuff plus about 12,000 other things you've never even heard of. That's the way used to be. That makes it easier to work with older programs that expect to have everything on the floor, but that's really the only reason to use it (that and teaching newbies C++).
Statements like "using std::vector" are the more civilized, more correct way of doing things. Think of them as taking a specific item out of the box and using it. It's more explicit, it's neater, it enforces the "least access" ideal, and it's just all around better practice.
Instead of "using namespace std;", you can also state "using std::cout;", "using std::vector;", etc.. That way you don't get the "dumped box" effect, and you still save some typing.
Wow that is great guys !!! You've all been of a big help. My lecturer haven't explained a thing on it and I'm curious as always why the heck is that routine for?!?! You guys are so smart and cool, god how I wish I could master C++ one day to know as many as most of you here. Now I understad where how those vectors and strings were used to work under std, that is just great gathering more and more knowledge with time not just from lecturers , but and from you guys. By the way, chipperMDW,...you're speach was just very clear, smart, interesting and intelligent....aren't you a lecturer yourself? You seem to rock ^_^
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.