I can't integrate the header file

Jul 30, 2016 at 4:51am
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 Jul 30, 2016 at 5:06am
Jul 30, 2016 at 6:24am
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 Jul 30, 2016 at 6:26am
Jul 30, 2016 at 6:28am
@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.
Jul 30, 2016 at 8:07am
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
Jul 30, 2016 at 12:39pm
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.
Jul 30, 2016 at 2:20pm
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.
Jul 30, 2016 at 2:33pm
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 Jul 30, 2016 at 2:47pm
Jul 30, 2016 at 2:59pm
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.
Jul 30, 2016 at 2:59pm
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.
Jul 30, 2016 at 3:12pm
closed account (E0p9LyTq)
For BEGINNERS, yes, for VERY specific reasons. Being lazy #1.

But for production code? Not at all.

Jul 30, 2016 at 6:34pm
I fully agree.
Aug 11, 2016 at 9:21pm
Back to the poster's problem. Try typing the full path to the header file.
Topic archived. No new replies allowed.