Frank Looper wrote:
#include <iostream>
using namespace std;
This is a very bad idea. Try to avoid ever putting 'using' directives
in a header.
Isn't that the standard?
The standard what?
It's at least being taught as such...
Change your teacher/book.
Unfortunately, I don't see the post you are a answering to, so I am
assuming there was a using declaration in a header.
Putting a using declaration in a header allows for side-effects. For
example, if I include <a_math_library.h>, I assume I'll get some
math-related functions, not the whole namespace std (or whatever
namespace for that matter). Just look :
# include <list>
// the name 'list' is not recommended, but shit happens
//
class list
{
// ...
};
int main()
{
list my_list;
std::list a_std_list;
}
Now that works. But now we got that new and cool math library and we
include it
# include <list>
# include <a_math_library.h>
// same thing..
but that header begins with
# include <cmath>
using namespace std;
That means our code will break beacuse we included an unrelated header.
That's an unpleasant side effect.
What's more, the usual warning about using declarations also applies:
they defeat the very purpose of namespaces, which is to avoid name
clashes. Using directives are better, using directives at function
scope in implementation file are the best.
# include <iostream>
int main()
{
using std::cout;
cout << "Here we are.";
}
Jonathan