⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_49450.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:49450 发表者:鹏程 发表日期:2003-08-10 20:45:56
<br>主题:我是vc初学者请教大侠
<br>内容:请问:<BR>#include"*.h"与#include&lt;*.h&gt;有什么区别?为什么书上有的语句用#include"*.h",而有的语句用#include&lt;*.h&gt;?
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:木一 回复日期:2003-08-10 21:42:02
<br>内容:简单的说:VC集成环境里,已经设置了默认的头文件存放的位置,你可以从这里看到:<BR><BR>与Visual Studio 6为例:<BR>Tools|Options [Directories]<BR>你可以看到头文件[Include],库文件[LIB],源文件[Source]等的路径。<BR><BR>当你包含系统提供的头文件的时候,尽量用 <BR>#include &lt;afx.h&gt;而不要用#include "afx",这样可以让你有一个好的编程风格。<BR><BR>#include "xxx.h"的意思是先在你的工作区的当前目录下面找对象xxx.h头文件,如果没找到,就按顺序在Tools|Options [Directories]指明的地方去找。<BR><BR><BR><BR><BR>The #include Directive<BR>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. 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 only need to define and name the types once in an include file created for that purpose.<BR><BR>Syntax<BR><BR>#include "path-spec"<BR><BR>#include &lt;path-spec&gt;<BR><BR>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.<BR><BR>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.<BR><BR>Syntax Form Action <BR>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 whatever 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. <BR>Angle-bracket form This form instructs the preprocessor to search for include files first along the path specified by the /I compiler option, then along the path specified by the INCLUDE environment variable. <BR><BR><BR>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 two sets of double quotation marks (" "), the preprocessor searches only that path specification and ignores the standard directories.<BR><BR>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.<BR><BR>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.<BR><BR>When include files are nested, 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. <BR><BR>The following example shows file inclusion using angle brackets:<BR><BR>#include &lt;stdio.h&gt;<BR><BR>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.<BR><BR>The following example shows file inclusion using the quoted form:<BR><BR>#include "defs.h"<BR><BR>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.<BR><BR>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.<BR><BR>Microsoft Specific <BR><BR>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.<BR><BR>For example, the command<BR><BR>CL /ID:\MSVC\INCLUDE MYPROG.C<BR><BR>causes the preprocessor to search the directory D:\MSVC\INCLUDE for include files such as STDIO.H. The commands<BR><BR>SET INCLUDE=D:\MSVC\INCLUDE<BR>CL MYPROG.C<BR><BR>have the same effect. If both sets of searches fail, a fatal compiler error is generated.<BR><BR>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.<BR><BR>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.<BR><BR>END Microsoft Specific<BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:佳明 回复日期:2003-08-10 21:50:38
<br>内容:编译时查找*.h文件的顺序不一样,比如VC自带有头文件stdio.h ,<BR>而你自已也写了一个叫stdio.h的文件,放在自己这个程序的文件夹里,<BR>用#include "stdio.h"引用的就是你自己写的那个,<BR>用#include &lt;stdio.h&gt;引用的就是VC带的那个<BR>如果你没用自己的头文件代替VC的头文件,就是一样的,<BR>用#include "*.h"的形式一般是没有问题的,也有利于使用新版本的头文件。<BR>如果你明确要用的是VC自带的标准的版本,用#include &lt;*.h&gt;也挺好 <BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:张庆芳 回复日期:2003-08-10 23:05:40
<br>内容:2楼言简意赅,是正确答案。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:鹏程 回复日期:2003-08-11 01:09:46
<br>内容:我装的是盗版的VC6,没有找到“Tools|Options [Directories]”文件夹,但在VC98文件夹中找到了“头文件[Include],库文件[LIB]”等的路径。因此一楼的意思我明白了。<BR>二楼的意思更通俗更具体。<BR>因此请教朋友们,怎样才能将一楼和二楼都选中,都接受为正确的答案?
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:佳明 回复日期:2003-08-11 07:50:33
<br>内容:是不是创天中文版?在打开 工具-&gt;选择 对话框,里面有一个“目录”标签页,就是了<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:鹏程 回复日期:2003-08-11 08:59:48
<br>内容:我装的是英文版的VC6,可是我不懂英文。现在在5楼的提示下,我在菜单Tools-&gt;菜单Options-&gt;标签页Directories中看到了三个包含“头文件[Include],库文件[LIB]”等的路径:1)C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE,2)C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE,3)C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE。<BR>非常感谢朋友们的帮助!
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -