STD

Every post I have posted thus far, everyone responds with code that enacts std prior to entering each function. I am new, and in a CIS intro course, and they have only told me to enter "using namespace std" once in the header. What is the difference?
There is no intended difference. Writing the statement only once is less redundant. Redundancy in code is a bad thing.
See the DRY principle: https://en.wikipedia.org/wiki/Don%27t_repeat_yourself

Of course, it is an unequivocally terrible idea to put using directives in header files.

Doing so has the potential to silently change the behavior of all the code which includes the contents of that header file. These problems can appear because of the interactions between name collisions and overload resolution, and will cause "unintended" semantic differences that manifest differently on different machines and different implementations.

It certainly sucks when doing this causes a compilation error or a bug on only your TA's machine.
Last edited on
Awesome. Thanks!
Topic archived. No new replies allowed.