1

I started reading a well known book called Programming: principles and practice in c++. But the first program that was included in a book looked like that. Now, there are 2 problems. Line #include "std_lib_facilities.h" my compiler doesn't recognise as a valid code (I thought you should write include iostream) and down where the code cout is, wasn't there seposed to be a code named using namespace std; for the code cout to be written in short version.

#include "std_lib_facilities.h" 

int main()
{ 
    cout << "Hello, World!\n";
    return 0; 
}
1

2 Answers 2

3

Copy the header file from here. Save the file in the same directory as your code with the name std_lib_facilities.h. After that your code should compile.

As you can read from the file, #include <iostream> and using namespace std; are already included so you don't have to write them again.

In C++, including header files is almost equivalent to copying everything from the header file and paste it to where the header is included.

2
  • But why would i have to do all that if you could just simpy write a code inlcude iostream. Also, is this book good for the beginners like me. Commented Feb 4, 2016 at 15:35
  • You could do that, but since you are following instructions from a book, the book might want you to use other things in the given header file.
    – SegFault
    Commented Feb 4, 2016 at 21:18
2

You should copy the header std_lib_facilities.h from the Stroustrup site. You can find the reference to the site in the book.

(Or look here )

Now you can just substitute this include for

#include <iostream>

using namespace std;
12
  • A better practice is list the std items separately: using std::cout;. Thus not including the entire std namespace. Commented Feb 4, 2016 at 15:27
  • @ThomasMatthews The derictives I showed are included in the header of Stroustrup.:) Commented Feb 4, 2016 at 15:28
  • Which is one more reason not to use it. I get that he did it for the examples in the book to make them smaller but it runs against current coding practices. Commented Feb 4, 2016 at 15:30
  • But why would i have to do all that if you could just simpy write a code inlcude iostream. Also, is this book good for the beginners like me. Commented Feb 4, 2016 at 15:32
  • @ŽigaGazvoda This header will be required for other programs shown in the book. Commented Feb 4, 2016 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.