1. C 语言的头文件 :
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
2. C++语言的头文件
#include <iostream>
#include <string>
#include <queue>
3. 最大差异就是没有 *.h
4. 主要文件 main.c app.c app.h 三种函数的标准写法
// ===== main.h =====
include <iostream.h>
using namespace std;
#include "app.h"
5. 自定义头文件内容只能够存在
(1) extern 变量 声明
(2) 函数 声明
6. 自订义 *.cpp
(1) 变量要拿来 定义
(2) 函数要拿来 实现
7. 如何防止重负包含头文件
预编译指令
#ifndef _HEADERNAME_H
#define _HEADERNAME_H
...
#enif
8. 全部内容 :
int main(void)
{
int answer;
int b = 300;
answer = sum(a, b);
cout << "Hello Header Files Project Demo\n" << endl;
cout << "sum(a,b) = " << answer << endl;
}
===========================
int a = 100;
unsigned int sum(unsigned int a, unsigned int b)
{
unsigned int temp;
temp = a + b;
return temp;
}
====================================
#ifndef __APP__H__
#define __APP__H__
extern int a;
unsigned int sum(unsigned int a, unsigned int b);
#endif