【问题标题】:Is c++ std_lib_facilities.h still used?c++ std_lib_facilities.h 还在使用吗?
【发布时间】:2018-02-03 06:00:38
【问题描述】:

我正在从 Bjarne Stroustrup 的《编程:原则与实践》中学习 C++。他们给出了一个示例程序:

// read and write a first name
#include "std_lib_facilities.h"
int main()
{
    cout << "Please enter your first name (followed by 'enter'):\n";
    string first_name; // first_name is a variable of type string
    cin >> first_name; // read characters into first_name
    cout << "Hello, " << first_name << "!\n";
}

当我在 Visual Studio 中键入相同的代码时,头文件“std_lib_facilities.h”出现错误。我糊涂了 用这个头文件。

还在用吗?我还能用什么来代替这个标题?

【问题讨论】:

  • 这从来不常用。它是专门为那本书(或者更准确地说,是伴随它的课程)编写的。
  • 我认为这可能是 this question 的副本,因为它在那里得到了回答,但是这两个问题有很大的不同,以至于我不愿意以具有约束力的投票结束,所以我会把链接留在这里。
  • 那么,我应该如何阅读那本书?我应该修改代码吗?
  • @ArtemyVysotsky: &lt;string&gt; 是此"std_lib_facilities.h" 间接包含的标头之一
  • 如果错误是“std_lib_facilities.h”正在使用已弃用或过时的标头。您可能想在这里尝试更新版本github.com/BjarneStroustrup/…

标签: c++ visual-studio c++11


【解决方案1】:

在这本书的附录(具体为 C.3.2)中 - Programming: Principles and Practice Using C++ -,你实际上可以找到作者解释这个特定的头文件 - std_lib_facilities.h,他留下了一个链接读者下载(http://www.stroustrup.com/Programming/std_lib_facilities.h)。

由于学习者必须下载文件并将其放置在您选择的目录中,我由此推断该文件不是人们实际使用的头文件,而仅用于教学用途。

【讨论】:

  • 本书中确实给出了这个链接,但它指向的是旧版本的std_lib_facilitied.h,它可能会给出错误信息。最新版本可以在http://www.stroustrup.com/Programming/PPP2code/std_lib_facilities.h 或用户 Jon 在 OP 下的 cmets 中提到的 githuspage 上找到。另请参阅此相关question
  • @Ernie060 您的链接似乎不起作用。您的评论只有 1.5 个月大。也许最近发生了一些变化。
  • @MarkMiller 感谢您指出这一点。我相信该链接有效,因为我在阅读《原则和实践》一书时进行了尝试。看来www.stroustrup.com/Programming 的整个部分不再起作用了......然后应该参考 Jon 提到的 gibhub 页面。
【解决方案2】:

Bjarne Stroustrup 在 Programming : Principles and practice using c++ 中列出的链接 已过时。 事实上,Stroustrup 网站的整个部分,https://stroustrup.com - https://stroustrup.com/programming 已经过时了,你也不会在网站主页上的任何地方找到它。

正如 Jon 所说,您可以在这里找到更新的工作版本的 github 存储库:https://github.com/BjarneStroustrup/Programming-_Principles_and_Practice_Using_Cpp/blob/master/std_lib_facilities.h

要使用此文件,请从存储库中复制代码并打开文件资源管理器。转到计算机上安装 MinGw 的文件夹(如果您的 PC 上安装了 MinGw),如果没有,请从此处下载 MinGw:https://sourceforge.net/projects/mingw-w64/

在此处查看 MinGw 的安装过程:https://www.youtube.com/watch?v=bhxqI6xmsuA

安装 MinGw 后,转到您安装 MinGw 的文件夹,然后单击您在其中看到的包含文件夹。在那里,创建一个新的文本文件(单击新项目-> 文本文件)并将您从 github 存储库复制的代码粘贴到那里。将文件另存为 std_lib_facilities.h 并关闭文件资源管理器。

现在您的代码将毫无问题地运行!

希望这个答案对你有所帮助!

【讨论】:

    【解决方案3】:

    来自 Bjarne Stroustrup 的网站 (Homepage)

    实际上 std_lib_facilities.h 的原始 URL 是: https://www.stroustrup.com/Programming/PPP2code/std_lib_facilities.h
    但截至撰写本文时,它给出了 404 Not Found Error。

    但是,如果我们从 URL 的路径中删除“Programming”一词以使其: https://www.stroustrup.com/PPP2code/std_lib_facilities.h
    我们从官网获取库的代码。

    希望将来 Stroustrup 先生能纠正这个问题。

    【讨论】:

      【解决方案4】:

      这是您正在使用的书中的引述:

      如何找到 std_lib_facilities.h?如果您正在上课,请询问您的讲师。如果没有,请从我们的支持网站www.stroustrup.com/Programming 下载。但是,如果您没有讲师并且无法访问网络怎么办?在这种情况下(仅),将#include 指令替换为

          #include <iostream>
          #include <string>
          #include <vector>
          #include <algorithm>
          #include <cmath>
          using namespace std;
          inline void keep_window_open() { char ch; cin >> ch; }
      

      请注意,using namespace std; 是一个糟糕的建议(尽管来自 C++ 发明者本人的口),你永远不应该使用这行代码。相反,您应该在所有标准库函数和类前面加上 std::。这样你的程序就变成了(在上面的#include 指令之后):

      int main()
      {
          std::cout << "Please enter your first name (followed by 'enter'):\n";
          std::string first_name; // first_name is a variable of type string
          std::cin >> first_name; // read characters into first_name
          std::cout << "Hello, " << first_name << "!\n";
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-02-04
        • 2021-12-22
        • 1970-01-01
        • 1970-01-01
        • 2011-06-27
        • 2017-09-12
        • 1970-01-01
        • 2018-10-27
        相关资源
        最近更新 更多