首页 文章

编程:c - cout问题的原则和实践

提问于
浏览
1

我开始阅读一本名为 Programming: principles and practice in c++ 的着名书籍 . 但是书中包含的第一个程序看起来就是这样 . 现在,有两个问题 . 行 #include "std_lib_facilities.h" 我的编译器没有't recognise as a valid code (I thought you should write include iostream) and down where the code cout is, wasn' t设置为使用命名空间std命名的代码;代码cout用短版本编写 .

#include "std_lib_facilities.h" 

int main()
{ 
    cout << "Hello, World!\n";
    return 0; 
}

2 回答

  • 2

    here复制头文件 . 将文件保存在与代码相同的目录中,名称为 std_lib_facilities.h . 之后你的代码应该编译 .

    正如您可以从文件中读取的那样,已经包含了 #include <iostream>using namespace std; ,因此您无需再次编写它们 .

    在C中,包括头文件几乎等同于从头文件复制所有内容并将其粘贴到包含头的位置 .

  • 3

    您应该从Stroustrup站点复制 Headers std_lib_facilities.h . 您可以在书中找到对该网站的引用 .

    (或者看here

    现在你可以用这个包括替换

    #include <iostream>
    
    using namespace std;
    

相关问题