“ std_lib_facilities.h”;显示错误 [英] "std_lib_facilities.h" showing error

查看:445
本文介绍了“ std_lib_facilities.h”;显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Codeblocks 17.12,并且已经将编译器设置设置为C ++ 11标准。我正在学习Bjarne Stroustrup的书编程-使用C ++的原理和实践。在他的书中,他要求包括 std_lib_facilities.h。我从他的网站复制了该文件,并将其保存在 Mingw文件夹的 include文件夹中。之后,我开始制作一个简单的程序:

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 using C++". In his book he asked to include "std_lib_facilities.h". I copied it from his website and saved in "include" folder of "Mingw" folder. After that I proceeded to make a simple program:

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

但是编译器显示以下错误和警告:

But the compiler is showing following errors and warnings:


 warning: This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date.  
 Please use a non-deprecated interface with equivalent functionality instead. 
 For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated. [-Wcpp]

 error: template-id 'do_get<>' for 'String > 
   std::__cxx11::messages<char>::do_get(std::messages_base::catalog, int, int, const String&) const' does not match any template declaration

 note: saw 1 'template<>', need 2 for specializing a member function template


也显示的错误是在头文件 locale_facets_nonio.h 的1971行中。

我试图在其他论坛中找到解决此问题的方法,但找不到满意的答案。

有人说我们不应该使用此文件 std_lib_facilities.h 完全一样,因为它使用的是不推荐使用或过时的标头。

Also the error which is showing is in the 1971 line of the header file "locale_facets_nonio.h".
I tried to find out the solution to this problem in other forums, but could not find a satisfactory answer.
Some are saying we should not use this file "std_lib_facilities.h" at all as it is using deprecated or antiquated headers.

推荐答案


我们完全不应使用此文件 std_lib_facilities.h,因为它已弃用或陈旧的标题。

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

使用标准标头时,应 #include std_lib_facilities.h 可能会不同步。

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";
}

宁可

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

使用更多标准功能,例如 std :: string 应该是:

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

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






进一步扩展,阅读在您的书籍示例中, #include std_lib_facilities.h 应该可以扩展为可编译和高效代码所必需的标准标头。

这只是一个 Coliru


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;
}

确定您可以收集

#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.

另一个相关的问答:

为什么我不应该#include< bits / stdc ++。h>?

这篇关于“ std_lib_facilities.h”;显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆