This question already has an answer here:
这个问题在这里已有答案:
- Why do some includes need the .h and others not? 3 answers
为什么有些人需要.h而其他人不需要? 3个答案
i know we always include a header files, then why do i find some header files like
我知道我们总是包含一个头文件,那为什么我会找到一些头文件
#include<iostream>
with no .h extension but some header files like
没有.h扩展名但是有些头文件
#include<windows.h>
with the .h extension and i also tried to add.h to some header files like iostream.h but that didnt work, so what's the difference between adding a .h extension when includeing a file andnot doing this.
使用.h扩展名,我也尝试将add.h添加到某些头文件,如iostream.h,但是没有用,所以在包含文件时添加.h扩展名而不执行此操作之间的区别是什么。
thanks for all replies... much appreciated
感谢所有的回复...非常感谢
3 个解决方案
#1
5
It simply depends on the particular header.
它只取决于特定的标题。
The standard library headers (like <iostream>
) do not have an extension - just use the name.
标准库头文件(如
For other header files (strictly formally, these shouldn't be called "headers," but "included source files"), it's whatever the file's author decided to use. So windows.h
uses extension .h
. Boost prefers .hpp
on its files. .hh
or .hxx
is also commonly used for C++, but if the header file's author decides to use myHeader.IamBob
, you will have to:
对于其他头文件(严格来说,这些不应该被称为“标题”,而是“包含的源文件”),它是文件作者决定使用的任何文件。所以windows.h使用扩展名.h。 Boost更喜欢.hpp文件。 .hh或.hxx也常用于C ++,但如果头文件的作者决定使用myHeader.IamBob,则必须:
#include <myHeader.IamBob>
#2
1
You always need to specify the exact file name. There is no "implicit" .h
. For a standard conforming implementation, the c++ libraries have no extension.
您始终需要指定确切的文件名。没有“隐含的”.h。对于标准符合实现,c ++库没有扩展名。
Therefore
#include <iostream>
is valid and conforming, while
是有效的,符合,而
#include <iostream.h>
may be accepted by your compiler (or your neighbours), but it isn't portable nor is it guaranteed to be identical or compatible with iostream
.
您的编译器(或您的邻居)可能会接受它,但它不可移植,也不保证与iostream相同或兼容。
#3
0
The iostream.h header used to be common before C++ was first standardized in 1998. But since the 98 standard used instead of , the latter has fallen out of favor (being non-standard and all) and is no longer supported on all platforms. Code that uses it should be considered non-standard legacy code and is not portable. include <iostream>
, not <iostream.h>
(the latter is deprecated)
在C ++于1998年首次标准化之前,iostream.h标头曾经是常见的。但是由于使用的是98标准,后者已经失宠(非标准和全部)并且不再支持所有平台。使用它的代码应被视为非标准遗留代码,并且不可移植。 include
#1
5
It simply depends on the particular header.
它只取决于特定的标题。
The standard library headers (like <iostream>
) do not have an extension - just use the name.
标准库头文件(如
For other header files (strictly formally, these shouldn't be called "headers," but "included source files"), it's whatever the file's author decided to use. So windows.h
uses extension .h
. Boost prefers .hpp
on its files. .hh
or .hxx
is also commonly used for C++, but if the header file's author decides to use myHeader.IamBob
, you will have to:
对于其他头文件(严格来说,这些不应该被称为“标题”,而是“包含的源文件”),它是文件作者决定使用的任何文件。所以windows.h使用扩展名.h。 Boost更喜欢.hpp文件。 .hh或.hxx也常用于C ++,但如果头文件的作者决定使用myHeader.IamBob,则必须:
#include <myHeader.IamBob>
#2
1
You always need to specify the exact file name. There is no "implicit" .h
. For a standard conforming implementation, the c++ libraries have no extension.
您始终需要指定确切的文件名。没有“隐含的”.h。对于标准符合实现,c ++库没有扩展名。
Therefore
#include <iostream>
is valid and conforming, while
是有效的,符合,而
#include <iostream.h>
may be accepted by your compiler (or your neighbours), but it isn't portable nor is it guaranteed to be identical or compatible with iostream
.
您的编译器(或您的邻居)可能会接受它,但它不可移植,也不保证与iostream相同或兼容。
#3
0
The iostream.h header used to be common before C++ was first standardized in 1998. But since the 98 standard used instead of , the latter has fallen out of favor (being non-standard and all) and is no longer supported on all platforms. Code that uses it should be considered non-standard legacy code and is not portable. include <iostream>
, not <iostream.h>
(the latter is deprecated)
在C ++于1998年首次标准化之前,iostream.h标头曾经是常见的。但是由于使用的是98标准,后者已经失宠(非标准和全部)并且不再支持所有平台。使用它的代码应被视为非标准遗留代码,并且不可移植。 include