“std_lib_facilities.h"显示错误

quot;std_lib_facilities.hquot; showing error(“std_lib_facilities.h显示错误)

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

问题描述

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

#include#include std_lib_facilities.h"主要的(){std::cout<<"Hello world";}

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

<块引用>

 警告:此文件包含至少一个已弃用或过时的标头,将来可能会在不另行通知的情况下将其删除.请改用具有等效功能的非弃用接口.有关替换标头和接口的列表,请参阅文件 backward_warning.h.要禁用此警告,请使用 -Wno-deprecated.[-Wcpp]错误:模板 ID 'do_get<>'对于'字符串>std::__cxx11::messages<char>::do_get(std::messages_base::catalog, int, int, const String&) const' 不匹配任何模板声明注意:saw 1 'template<>',需要 2 来专门化成员函数模板

显示的错误也在头文件 "locale_facets_nonio.h" 的 1971 行中.
我试图在其他论坛中找到解决此问题的方法,但找不到满意的答案.
有人说我们根本不应该使用这个文件 "std_lib_facilities.h",因为它使用了已弃用或过时的标头.

解决方案

我们根本不应该使用这个文件std_lib_facilities.h",因为它使用了已弃用或过时的头文件.

您应该在使用它们时#include 标准标题.std_lib_facilities.h 可能会不同步.

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

应该是

#include//#include "std_lib_facilities.h" 完全删除它!int main() {std::cout<<"Hello world";}

使用像 std::string 这样更标准的功能应该是:

#include#include<字符串>int main() {std::string hello = "你好世界";std::cout<<你好;}

<小时>

进一步扩展,阅读您的书籍示例中的 #include std_lib_facilities.h 可能应该变成为您的可编译和生产代码扩展实际必要的标准头文件.
这只是 Coliru

使用的默认起始模板

#include <iostream>#include <向量>模板<类型名 T>std::ostream&运算符<<(std::ostream& os, const std::vector<T>& vec){for (auto&el: vec){os <

当然可以收集

#include <iostream>#include <向量>

在一个单独的头文件中,但要与您的所有翻译单元保持同步会很乏味.

<小时>

另一个相关的问答:

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

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

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.

解决方案

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>?

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

本文标题为:“std_lib_facilities.h"显示错误

基础教程推荐