1

I have this webapge:

http://www.stroustrup.com/Programming/PPP2code/std_lib_facilities.h

I'm completing a book by Stroustrup and want to do what I need to do so that I can begin my programs with,

#include "std_lib_facilities.h"

Rather than,

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

What do I need to do?

Bryant
  • 324
  • 2
  • 15
  • Right-click that link you just provided, select 'Save link as', and save the file to the same directory where your source code is. – Benjamin Lindley Jul 20 '17 at 03:14
  • I'm saving my source code to a folder on my desktop. I tried adding the .h file to that folder, modifying the source code to use #include "std_lib..." instead of namespace, and running it, but I got a "file not found" error message for "std_...". – RobotSenior Jul 20 '17 at 03:23
  • You really ought to avoid `using namespace std` - it is a bad habit to get into, and [can silently change the meaning of your program](/q/1452721) when you're not expecting it. Get used to using the namespace prefix (`std` is intentionally very short), or importing *just the names you need* into the *smallest reasonable scope*. – Toby Speight Jan 10 '19 at 17:48

1 Answers1

0

The header file must be in the same directory where the source code file is. Here is the explanation from https://www.stroustrup.com/programming_support.html

Note that different compilation systems and programmer communities have different conventions for where to put header files. The book assumes that a header file is in the same directory/folder as the .cpp files and uses "plain" #include "std_lib_facilities.h". If that doesn't work, try #include "../std_lib_facilities.h" (one level up) and #include "../../std_lib_facilities.h" (two levels up).

RomanK
  • 101
  • 4
  • note that the link is a 403 – Mike 'Pomax' Kamermans Jan 21 '22 at 20:26
  • @Mike'Pomax'Kamermans please note that the answer was provided in 2019 and the relevant information is quoted. The link was working back then and it is referred to in the book on page53. – RomanK Jan 22 '22 at 22:53
  • I know. However, as on of SO's practices to keep answers relevant for future visitors, if there is no alternative link, better to remove it since it's now locked down, or update it to a still working link if there is one. (and it looks like you updated it so: great, on behalf of future visitors, thank you) – Mike 'Pomax' Kamermans Jan 23 '22 at 00:17