百韵网 >>  正文

C++ 读别人的程序,制作了下面的头文件,包含在主程序当中,但是我读不懂啊,好多不认识,求大神给解释! 我在VS2005中编写了一个程序,自己制作了头文件和源文件,...

来源:www.baiyundou.net   日期:较早时间
前三行注释,没用
#if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
#define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_
就是这个(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)没有定义的话,下面定义一下
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
这一段的意思是如果
_MSC_VER > 1000这个条件满足
就执行#pragma once
#pragma once的作用防止头文件重复包含

#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers

// Windows Header Files:
#include <windows.h>
#include <process.h> /* _getpid() */
#include <shellapi.h> /* ShellExecute() */
这一段要用到的是window系统内的函数,所以先声明,后面的几个.h文件是调用的是window系统中的函数

// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <stdio.h> /* sprintf() */
#include <oledlg.h> /* OPENFILENAME */
这一段类似,是用到C语言中(编译器中)的函数,下面的.h是调用那些函数
// Local Header Files

// TODO: reference additional headers your program requires here

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
这一段也是没用的东西,注释

最后就是定义结束了
#endif // !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
反正你只要看到/* */和// 就是注释,没起任何作用
头文件的作用在编译器中都会有说明,或者百度一下都可以找到,个人建议去编译去中看

#if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)/* 如果没定义(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_),则执行下边的宏定义语句*/
#define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_

#if _MSC_VER > 1000 /*如果表达式成立,则执行下边的语句,即#pragma once*/
#pragma once /*让头文件只编译一次,防止头文件重复包含*/
#endif // _MSC_VER > 1000

#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers

// Windows Header Files:
#include <windows.h>

#include <process.h> /* _getpid() */
#include <shellapi.h> /* ShellExecute() */

// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <stdio.h> /* sprintf() */
#include <oledlg.h> /* OPENFILENAME */

// Local Header Files

// TODO: reference additional headers your program requires here

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)

后边的都类似了,一些是包含的.H文件,还有和上边一样的预处理命令

diwutian1124 已经基本回答了你的问题,至于你的追问,包含 .H文件的意思(#include) 就是编译器会将 .h文件在 include 出加载进来编译, 相当于在当前文件中定义的一样。.h文件的定义在当前文件中都是可以直接是用的。

我在VS2005中编写了一个程序,自己制作了头文件和源文件,再在主函数的文件里包含头文件,但是调用不了自~

08和VS2010。我将下面程序运行了一下:

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
vector<int> ivec;

for (int i = 0; i < 10; ++i)
ivec.push_back(i);

if (std::is_sorted(ivec.begin(), ivec.end()))
cout << "Support!" << endl;
else
cout << "Not Support!" << endl;
}
发现:2010可以通过编译,2008则不行!
于是我又查了《C++标准程序》一书,发现上面也没有,初次判断is_sorted不是98标准的内容。
我又查看了最新的C++0x标准草稿N3225,果然发现了~由于我没有98标准,所以不能够断定is_sorted不是98的内容,但是我在google上的一些英文网站上得知与我预测的差不多~(虽然在一个网站上差到说SGI版本的STL有is_sorted函数,但是我在侯捷的《STL源码剖析》中仍未找到,进一步肯定了不是98标准的内容)!
所以,is_sorted是C++0x新标准里边的内容,虽然标准还没有面世,但是Visual Studio 2010已经实现了部分新标准的内容!
还有你可以在VS2005下使用另一种替换方式(如果你很像用STL来实现这一功能):
adjacent_find(begin(), end(), greater_than<T>()) == end()
来代替
is_sorted(begin(), end())
另外,团IDC网上有许多产品团购,便宜有口碑

你这个代码中80%都是被注释掉了
// mergenew.h : main header file for the MERGENEW application#if !defined(AFX_MERGENEW_H__1413D7E4_1C04_11D6_A92C_99DC52C52B48__INCLUDED_)#define AFX_MERGENEW_H__1413D7E4_1C04_11D6_A92C_99DC52C52B48__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000#ifndef __AFXWIN_H__#error include 'stdafx.h' before including this file for PCH#endif#include "resource.h" // main symbols/////////////////////////////////////////////////////////////////////////////// CMergenewApp:// See mergenew.cpp for the implementation of this class//class CMergenewApp : public CWinApp //是个子类,继承了CWinApp{public: CMergenewApp(); //构造函数 // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CMergenewApp)public: virtual BOOL InitInstance(); //}}AFX_VIRTUAL // Implementation //{{AFX_MSG(CMergenewApp) afx_msg void OnAppAbout(); // NOTE - the ClassWizard will add and remove member functions here. // DO NOT EDIT what you see in these blocks of generated code ! //}}AFX_MSG DECLARE_MESSAGE_MAP()//一般来说看名字像消息响应函数};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_MERGENEW_H__1413D7E4_1C04_11D6_A92C_99DC52C52B48__INCLUDED_)

相关要点总结:
(编辑:本站网友)
相关推荐
关于我们 | 客户服务 | 服务条款 | 联系我们 | 免责声明 | 网站地图
@ 百韵网