是否仍在使用c ++ std_lib_facilities.h?

时间:2017-08-25 08:14:41

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

我从编程原理和实践中学习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中的类型相同时,它会给头文件带来错误。我很困惑 用这个头文件。

还在使用吗?还有什么我可以用而不是这个标题?

4 个答案:

答案 0 :(得分:3)

在本书的附录(具体而言为C.3.2)-编程:使用C ++的原理和实践-中,您实际上可以找到作者对此特定头文件进行说明-std_lib_facilities.h,他留下了一个链接读者下载(www.stroustrup.com/Programming/std_lib_facilities.h)。

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

答案 1 :(得分:1)

来自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先生会纠正此问题。

答案 2 :(得分:0)

Bjarne Stroustrup在“编程”中列出的链接:使用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 :(得分:0)

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

<块引用>

你如何找到 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";
}