I can't integrate the header file

Hi,

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.

I cant integrate this header file http://stroustrup.com/Programming/PPP2code/std_lib_facilities.h to my code. I have added it to the sector "headers" and have written in my source code
1
2
3
4
5
6
7
8
9
 

#include "std_lib_facilities.h"

int main()
{
	cout << "hello world" << endl;
	return 0;
}


But whenever I run the program my compiler sais cout, endl are not defined ad that the header could not be found

thanks
Last edited on
If you are just trying to use std::cout and std::endl. Instead of#include "std_lib_facilities.h" use#include <iostream>" .

If you really want to use that header make sure it is accessible by whatever compiler you are using to run it.
Last edited on
@Too Explosive

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.
The file std_lib_facilities.h needs to be in the same directory. Also endl is in the namespace std so use either:

using namespace std;
or
std::endl;
or
using std::endl
Also endl is in the namespace std so use either:

If he gets the #include problem fixed that include file has the using namespace std; statement.
that include file has the using namespace std; statement.

WOW, even the great expert uses it. Maybe some people here should think again about condemning it.
closed account (E0p9LyTq)
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.
Last edited on
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.
He still says it is not a good idea (PPP, 2nd Ed, 8.7.1, pg 297):

But it seems he recommends it for beginners.
closed account (E0p9LyTq)
For BEGINNERS, yes, for VERY specific reasons. Being lazy #1.

But for production code? Not at all.

I fully agree.
Back to the poster's problem. Try typing the full path to the header file.
Topic archived. No new replies allowed.