you know usingnamespace std in the global scope is a bad habbit, is it okay to put it in main or other blocks?

writing std: all the time is good practice i know but when im just putting something together to see if i learnt correctly its too tempting to just whack using namespace std at the top, bad habbit i know, specialy in practice of all places.

just theres not so likley going to be a namespace leak if you pop it between {} these right?

would that be a better habbit?
Remember you could do something like this inside main() or other function.
1
2
3
4
    using std::string;
    using std::printf;
    using std::cout;
    using std::endl;


That keeps the body of the code uncluttered as before, but gives much tighter control.
A better habit would be to use the "std::" prefix or a using declaration (like Chervil has provided above).
Last edited on
closed account (z05DSL3A)
Prefer Using Declarations to Using Directive but prefer full scope resolution to Using Declarations.

See the following for the differences between Using Declarations and Using Directive:
http://www.cplusplus.com/forum/beginner/9181/#msg42419
Topic archived. No new replies allowed.