I read the book programming principles and practice using c++ by bjarne stoustroup. He uses a header file with several instructions to simplify the practice.
But the author of the book includes all the fundamental instructions like #include <iostream> into the std_lib_facilties and also many further instructions for later.
It is a header with a mix of many commands to simplify the practice of the contents in this book.
He also only uses #include "std_lib_facilities.h" without typing #include <iostream>
But it is not working with my compiler although I have written the same commands as he has done.
WOW, even the great expert uses it. Maybe some people here should think again about condemning it.
He still says it is not a good idea (PPP, 2nd Ed, 8.7.1, pg 297):
The problem with overuse of using directives is that you lose track of which names come from where, so that you again start to get name clashes. Explicit qualification with namespace names (std::cout) and using declarations (using std::cout;) doesn’t suffer from that problem.
Maybe some people here should think again about condemning it.
I agree, when talking about very beginning programs. But when the program gets more advanced the use should be discouraged.
With respect to putting the using namespace std; statement into the header file, the author explains that this is a bad practice only used to ease the learning curve.
From Chapter 8:
"So, putting a namespace directive in a header file (so that users can't avoid it) is a very bad
habit. However, to simplify our initial code we did place a using directive in std_lib_facilities.h that
allowed use to write:
1 2 3 4 5 6 7 8 9 10
#include "std_lib_facilities.h"
int main()
{
string name;
cout << "Please enter your first name\n";
cin >> name;
cout << "Hello, " << name << '\n';
}
We promise to never do that for any namespace except std.