如何在c ++中创建自己的头文件?

时间:2013-11-16 06:48:05

标签: c++ c header

是否可以创建自己的新头文件?谁能帮助我如何用c ++创建我自己的头文件?

2 个答案:

答案 0 :(得分:27)

是的,当然可以,但在此之前,您需要了解哪些头文件以及如何正确使用它们。

file:yourname.h

#ifndef YOUR_NAME_INCLUDE
#define YOUR_NAME_INCLUDE

/* Your function statement here */
#endif

yourname.cpp

#include <iostream.h>
#include "yourname.h"

/* Your function definition here */

的main.cpp

#include <iostream.h>
#include "yourname.h"

/* Your function calling here */

要了解有关头文件和包含语句的更多信息,请单击下面的链接。

  

Header tutorial

答案 1 :(得分:4)

是的,您可以创建自己的头文件。

  1. 请通过bruce eckel vol 1在c ++中思考。
  2. 首先,头文件的扩展名为“.h”/“。hpp”
  3. 这些文件具有用户定义的数据结构和接口的声明,如类声明,函数原型等。
  4. 声明并将其存储到项目文件夹中。你需要在.cpp / .c中包含这个文件 例如:
  5. file:myheader.h

    #ifndef MYHEADER 
    #define MYHEADER
        ......
    #endif
    

    file:myclass.cpp

    #include <iostream.h>
    #include "myheader.h"