11

I'm learning C++ from Programming : Principles And Practice By Bjarne Stroustrup. They have given a sample program:

// read and write a first name
#include "std_lib_facilities.h"
int main()
{
    cout << "Please enter your first name (followed by 'enter'):\n";
    string first_name; // first_name is a variable of type string
    cin >> first_name; // read characters into first_name
    cout << "Hello, " << first_name << "!\n";
}

When I type the same code in visual studio, it gives error for the header file "std_lib_facilities.h". I'm confused with this header file.

Is it still used? What else can I use instead of this header?

r0gue
  • 115
  • 1
  • 1
  • 11
  • 11
    This was never commonly used. It was made up specifically for that book (or, more accurately, the course that accompanied it). – Cody Gray - on strike Aug 25 '17 at 08:15
  • I think this is probably a duplicate of [this question](https://stackoverflow.com/questions/42314399/dont-understand-errors-on-helloworld-in-vs-when-included-std-lib-from-stroustru) in that it is answered there, but the two questions are different enough that I don't feel comfortable closing with a binding vote, so I'll just leave the link here. – Cody Gray - on strike Aug 25 '17 at 08:19
  • so, how i should read that book? Should i modify the code? – r0gue Aug 25 '17 at 08:27
  • You can [obtain the header file](http://stroustrup.com/Programming/PPP2code/std_lib_facilities.h) and use it like the author intended, or you can rewrite the code the way a C++ programmer would normally write it, explicitly including the appropriate header files. For the standard stream-based I/O features, that would be `#include `. You'll need to consult another reference to figure out what these headers would be, though, since that book won't tell you. cppreference.com is probably a good bet; search for the name of the class you are trying to use. – Cody Gray - on strike Aug 25 '17 at 08:28
  • additionally this sample will require #include since std::string is used – Artemy Vysotsky Aug 25 '17 at 09:04
  • 1
    @ArtemyVysotsky: `` is one of the headers indirectly included by this `"std_lib_facilities.h"` – MSalters Aug 25 '17 at 09:17
  • When you get to chapter 8, Stroustrup will explain include files, scopes, and namespaces and why using a file like this is really a bad idea. It was added to the book so he could focus on the core language in the first chapters. – Bo Persson Aug 25 '17 at 09:58
  • 2
    If the error is that "std_lib_facilities.h" is using deprecated or antiquated headers. You might want to try the updated version here https://github.com/BjarneStroustrup/Programming-_Principles_and_Practice_Using_Cpp/blob/master/std_lib_facilities.h – Jon Jun 07 '19 at 15:49

4 Answers4

4

In the Appendices (C.3.2 to be specific) of the Book - Programming: Principles and Practice Using C++ -, you can actually find the author explaining about this specific header file - std_lib_facilities.h, and he left a link for the readers to download (http://www.stroustrup.com/Programming/std_lib_facilities.h).

Since learners must download the file and place it in a directory of your choice, I deduce from this point that the file is not a header file people would actually use, but solely for pedagogical uses.

milleniumbug
  • 15,379
  • 3
  • 47
  • 71
  • 4
    It is true that this link is given in the book, but it points to a old version of std_lib_facilitied.h, which might give error messages. The latest version can be found on [http://www.stroustrup.com/Programming/PPP2code/std_lib_facilities.h](http://www.stroustrup.com/Programming/PPP2code/std_lib_facilities.h) or at the githuspage that user Jon mentioned in the comments under the OP. See also this related [question](https://stackoverflow.com/questions/51313578/std-lib-facilities-h-showing-error) – Ernie060 May 04 '20 at 17:23
  • 2
    @Ernie060 your link does not seem to work. Your comment is only 1.5 months old. Perhaps something changed recently. – Mark Miller Jun 23 '20 at 07:52
  • 2
    @MarkMiller Thanks for pointing this out. I believe the link worked, because I tried it out while reading the principles and practices book. It seems that the whole part [www.stroustrup.com/Programming](https://www.stroustrup.com/Programming) doesn't work anymore... Then one should consult the gibhub page Jon mentioned. – Ernie060 Jun 23 '20 at 13:08
1

From the Website of Bjarne Stroustrup (Homepage)

Actually the original URL of the std_lib_facilities.h was: https://www.stroustrup.com/Programming/PPP2code/std_lib_facilities.h
But it gives 404 Not Found Error, as of the time this post was written.

However, if we remove the "Programming" word from the path of the URL to make it: https://www.stroustrup.com/PPP2code/std_lib_facilities.h
We get the code of the library from the official site.

Hope in future Mr. Stroustrup will rectify the issue.

Sourabh Choure
  • 723
  • 4
  • 15
0

The link that Bjarne Stroustrup listed in Programming : principles and practice using c++ is outdated. In fact, this whole section of Stroustrup's website , https://stroustrup.com - https://stroustrup.com/programming is outdated and you won't find it anywhere on the website's homepage too.

So as Jon mentioned, you can find the github repository for the newer, working version here : https://github.com/BjarneStroustrup/Programming-_Principles_and_Practice_Using_Cpp/blob/master/std_lib_facilities.h .

To use this file, copy the code from the repository and open file explorer. Go to the folder where MinGw is installed on your computer(if you have MinGw installed on your PC) if not, download MinGw from here : https://sourceforge.net/projects/mingw-w64/

See the installation process for MinGw here : https://www.youtube.com/watch?v=bhxqI6xmsuA

After installing MinGw, go to the folder where you have installed MinGw and click the include folder that you see in there. In there, create a new text file(click new item -> text file) and paste the code which you copied from the github repository there. Save the file as std_lib_facilities.h and close your file explorer.

Now your code will run without any problems!

Hope this answer helped you!

0

Here's a quote from the book you are using:

How do you find std_lib_facilities.h? If you are in a course, ask your instructor. If not, download it from our support site www.stroustrup.com/Programming. But what if you don’t have an instructor and no access to the web? In that case (only), replace the #include directive with

    #include <iostream>
    #include <string>
    #include <vector>
    #include <algorithm>
    #include <cmath>
    using namespace std;
    inline void keep_window_open() { char ch; cin >> ch; }

Note that using namespace std; is an awful advice (despite coming from the mouth of the C++ inventor himself) and you should never ever use this line. Instead, you should prefix all standard library functions and classes with std::. Thus your program becomes (after the #include directives above):

int main()
{
    std::cout << "Please enter your first name (followed by 'enter'):\n";
    std::string first_name; // first_name is a variable of type string
    std::cin >> first_name; // read characters into first_name
    std::cout << "Hello, " << first_name << "!\n";
}
n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243