"std_lib_facilities.h" showing error

There is an updated version of that file that works fine for the most recent revision of the ISO/IEC 14882 standard, namely C++17.

https://github.com/BjarneStroustrup/Programming-_Principles_and_Practice_Using_Cpp/blob/master/std_lib_facilities.h

You don't need that line:

#include<iostream> 

Hope you have not quit learning C++ with that wonderful book!


we should not use this file "std_lib_facilities.h" at all as it is using deprecated or antiquated headers.

You should #include standard headers as you use them. The std_lib_facilities.h might get out of sync.

#include<iostream>
#include "std_lib_facilities.h"
int main() {
    std::cout<<"Hello world";
}

should rather be

#include<iostream>
// #include "std_lib_facilities.h" Remove this entirely!
int main() {
    std::cout<<"Hello world";
}

Using more standard features like std::string should be:

#include<iostream>
#include<string>
int main() {
    std::string hello = "Hello world";
    std::cout<<hello;
}

Extending further, reading the #include std_lib_facilities.h in your books example should probably become to expand the actually necessary standard header includes for your compilable and productive code.
Here's just a default starting template as used by Coliru

#include <iostream>
#include <vector>

template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec)
{
    for (auto& el : vec)
    {
        os << el << ' ';
    }
    return os;
}

int main()
{
    std::vector<std::string> vec = {
        "Hello", "from", "GCC", __VERSION__, "!" 
    };
    std::cout << vec << std::endl;
}

Sure you could gather up the

#include <iostream>
#include <vector>

in a separate header file, but that would be tedious to keep in sync of what you need in particular with all of your translation units.


Another related Q&A:

Why should I not #include <bits/stdc++.h>?

Tags:

C++

Header