C++ 为什么我们在 Visual Studio 中编写 #include<iostream> 和 #include<conio.h>

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25883282/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 11:27:43  来源:igfitidea点击:

why we write #include<iostream> and #include<conio.h> in visual studio

c++visual-studio-2013

提问by Varun Moghe

In visual studio c++ consider the following code

在 Visual Studio C++ 中考虑以下代码

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    cout<<"Hello!";
    return 0;
    _getch();
}

In the above code in the #include<iostream>header file we dont use the .hextension because it produces an error.But in the header file #include<conio.h>the .hextension is added. Why does it produces error in case of #include<iostream>and not in case of #include<conio.h>If we write only conio it produces an error. And one more question why we use #include"iostream"header file when coutand cinare already included in namespace std

#include<iostream>头文件中的上述代码中,我们不使用.h扩展名,因为它会产生错误。但在头文件中添加#include<conio.h>.h扩展名。为什么它在 的情况下#include<iostream>而不是在 的情况下产生错误#include<conio.h>如果我们只写 conio 它会产生错误。还有一个问题,当coutcin已经包含在命名空间 std 中时,为什么我们使用#include"iostream"头文件

回答by Werner Erasmus

Prior to STL 98 standardization, most of the STL header files had (.h) file extensions. It was decided to remove to .h extension at some point in time. I'm not sure why this was decided, but possibly to provide uniqueness For more info, see.

在 STL 98 标准化之前,大多数 STL 头文件都有 (.h) 文件扩展名。决定在某个时间点删除到 .h 扩展名。我不确定为什么要这样做,但可能是为了提供独特性。有关更多信息,请参阅

conio.h is a Borland / MS specific header that contained console I/O functionality, and is not part of the standard.

conio.h 是 Borland / MS 特定的头文件,包含控制台 I/O 功能,并且不是标准的一部分。

Including standard files with .h extension is (still) allowed by some compilers, but is considered deprecated. The non extension version often forward include to extensions, and provide an extra layer that allows the "user" to be independent of the actual folder organization. This might be an additional reason.

某些编译器(仍然)允许包含具有 .h 扩展名的标准文件,但被视为已弃用。非扩展版本通常转发包含到扩展,并提供一个额外的层,允许“用户”独立于实际文件夹组织。这可能是一个额外的原因。