简体   繁体   中英

c++ #include (what functions are in what)

我是一个相当老练的Java程序员,所以我理解包括什么,以及为什么这样做,但是,我使用java作为一个例子,当我需要一个方法,我可以去结构,打开罐子,看看是什么在那里,但我一直在看一些tut,他们说你需要包含这个.h文件,因为它有这个功能等,所以问题:我键入#include <.h>并得到了所有的列表。 h文件,但是NOWHERE我看到那些文件中有什么,所以如果我需要使用一个获取系统属性的函数(只是一个例子),你怎么知道要包括什么,我现在真的不喜欢C出于这个唯一的原因。

functions do not exist in a header file (.h). They exist in .lib, .so, .dll etc files depending on whether they are static or dynamic and depending on the operating system. The header file just declares/prototypes the function. Typically the documentation of a function tells you which header it's declared in.

Header files are text files. You can open them in any text editor to see them, to see what functions they declare.

Typically, if the documentation doesn't tell me the header (rare), I go to the headers directory and either do a grep (on Linux/Unixes) or a findstr on windows to figure out where the function I want is declared.

Another thing to know is that including the right header file will help in compilation of your program but may not ensure that your program will link to build the final binary. For that you link with the right lib file. Again the documentation of the function will tell which is the right lib to link with. In the microsoft world, some header files may have a pragma lib entry which ensures that including the header automatically links in the right lib file.

A lot of the documentation is also available online - msdn, cppreference etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM