C++ 頭文件

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 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章