“std_lib_facilities.h” showing error

前端 未结 6 1704
一整个雨季
一整个雨季 2020-12-20 20:03

I am using Codeblocks 17.12 and have already set compiler settings to C++11 standard. I am studying from Bjarne Stroustrup\'s book \"Programming - Principles and Practice us

6条回答
  •  猫巷女王i
    2020-12-20 20:22

    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
    #include "std_lib_facilities.h"
    int main() {
        std::cout<<"Hello world";
    }
    

    should rather be

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

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

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

    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 
    #include 
    
    template
    std::ostream& operator<<(std::ostream& os, const std::vector& vec)
    {
        for (auto& el : vec)
        {
            os << el << ' ';
        }
        return os;
    }
    
    int main()
    {
        std::vector vec = {
            "Hello", "from", "GCC", __VERSION__, "!" 
        };
        std::cout << vec << std::endl;
    }
    

    Sure you could gather up the

    #include 
    #include 
    

    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 ?

提交回复
热议问题