扬州炒饭的简单做法:在C++中的#include<?>,<>里的?是有几个的,分别表示什么意思呢?

来源:百度文库 编辑:中科新闻网 时间:2024/05/06 04:03:23
在C++中的#include<?>,<>里的?是有几个的,分别表示什么意思呢?
我要中文的讲解,谢谢

想要多少有多少,你可以到
D:\Program Files\Microsoft Visual Studio\VC98\Include
目录下看看,所有.h的都可以

#include <iostream.h>
或者
#include "iostream.h"
是一样的

其中iostream.h是一个头文件的文件名
比如你在abc.cpp这个文件中定一了一个类
而你在编写其他代码的时候,你也想用到这个类,那么只要在这个代码前加上一句
#include "abc.cpp"
那么你就可以使用这个类了

我们用的cin和cout都是已经定义好的类,就在<iostream>里

头文件相当多,有从c语言中保留下来的库,也有c++中的标准模版库

现在的C++标准是用#include <iostream>取代#include <iostream.h>,具体好处自己去查书吧

这里边是头文件,有标准的头文件,也可以自己写,数量没法统计 多得很
不同的函数用到的头文件也可能不同
比如windows.h socket.h dos.h string.h
多得很

好像没有见过几个的
一般都是

#include "file.ext"
或者
#include <file.ext>

The #include directive tells the preprocessor to treat the contents of a specified file as if those contents had appeared in the source program at the point where the directive appears.

#include "path-spec"
#include <path-spec>

Remarks
You can organize constant and macro definitions into include files and then use #include directives to add these definitions to any source file. Include files are also useful for incorporating declarations of external variables and complex data types. You need to define and name the types only once in an include file created for that purpose.

The path-spec is a filename optionally preceded by a directory specification. The filename must name an existing file. The syntax of the path-spec depends on the operating system on which the program is compiled.

For information on how to reference assemblies in a C++ application compiled with /clr, see #using.

Both syntax forms cause replacement of that directive by the entire contents of the specified include file. The difference between the two forms is the order in which the preprocessor searches for header files when the path is incompletely specified.

Syntax Form Action
Quoted form
This form instructs the preprocessor to look for include files in the same directory of the file that contains the #include statement, and then in the directories of any files that include (#include) that file. The preprocessor then searches along the path specified by the /I compiler option, then along paths specified by the INCLUDE environment variable.

Angle-bracket form
This form instructs the preprocessor to search for include files first along the path specified by the /I compiler option, then, when compiling from the command line, along the path specified by the INCLUDE environment variable.

The preprocessor stops searching as soon as it finds a file with the given name. If you specify a complete, unambiguous path specification for the include file between double quotation marks (" "), the preprocessor searches only that path specification and ignores the standard directories.

If the filename enclosed in double quotation marks is an incomplete path specification, the preprocessor first searches the "parent" file's directory. A parent file is the file containing the #include directive. For example, if you include a file named file2 within a file named file1, file1 is the parent file.

Include files can be "nested"; that is, an #include directive can appear in a file named by another #include directive. For example, file2, above, could include file3. In this case, file1 would still be the parent of file2 but would be the "grandparent" of file3.

When include files are nested and when compiling from the command line, directory searching begins with the directories of the parent file and then proceeds through the directories of any grandparent files. Thus, searching begins relative to the directory containing the source currently being processed. If the file is not found, the search moves to directories specified by the /I compiler option. Finally, the directories specified by the INCLUDE environment variable are searched.

From within the development environment, the INCLUDE environment variable is ignored. To set the directories searched for include files (this information also applies to the LIB environment variable.), see VC++ Directories, Projects, Options Dialog Box.

The following example shows file inclusion using angle brackets:

Copy Code
#include <stdio.h>

This example adds the contents of the file named STDIO.H to the source program. The angle brackets cause the preprocessor to search the directories specified by the INCLUDE environment variable for STDIO.H, after searching directories specified by the /I compiler option.

The following example shows file inclusion using the quoted form:

Copy Code
#include "defs.h"

This example adds the contents of the file specified by DEFS.H to the source program. The double quotation marks mean that the preprocessor searches the directory containing the parent source file first.

Nesting of include files can continue up to 10 levels. Once the nested #include is processed, the preprocessor continues to insert the enclosing include file into the original source file.

Microsoft Specific

To locate includable source files, the preprocessor first searches the directories specified by the /I compiler option. If the /I option is not present or fails, the preprocessor uses the INCLUDE environment variable to find any include files within angle brackets. The INCLUDE environment variable and /I compiler option can contain multiple paths separated by semicolons (;). If more than one directory appears as part of the /I option or within the INCLUDE environment variable, the preprocessor searches them in the order in which they appear.

For example, the command

Copy Code
CL /ID:\MSVC\INCLUDE MYPROG.C

causes the preprocessor to search the directory D:\MSVC\INCLUDE for include files such as STDIO.H. The commands

Copy Code
SET INCLUDE=D:\MSVC\INCLUDE
CL MYPROG.C

have the same effect. If both sets of searches fail, a fatal compiler error is generated.

If the filename is fully specified for an include file with a path that includes a colon (for example, F:\MSVC\SPECIAL\INCL\TEST.H), the preprocessor follows the path.

For include files specified as #include "path-spec", directory searching begins with the directory of the parent file and then proceeds through the directories of any grandparent files. Thus, searching begins relative to the directory containing the source file containing the #include directive being processed. If there is no grandparent file and the file has not been found, the search continues as if the filename were enclosed in angle brackets.

END Microsoft Specific

See Also
Reference
Preprocessor Directives

To make a suggestion or report a bug about Help or another feature of this product, go to the feedback site.