用vs2015 自己写一个头文件并使用的方法

1.打开vs2015

2 新建项目

用vs2015 自己写一个头文件并使用的方法_第1张图片

 点 确定, 然后,点下一步

用vs2015 自己写一个头文件并使用的方法_第2张图片

完成

 

用vs2015 自己写一个头文件并使用的方法_第3张图片

3.添加源文件项

用vs2015 自己写一个头文件并使用的方法_第4张图片

添加

 

4.同理,添加头文件项,就一点不同

用vs2015 自己写一个头文件并使用的方法_第5张图片

5.添加相关代码

用vs2015 自己写一个头文件并使用的方法_第6张图片

可输入代码(c primer plus 中的一个例子)


// 2.h 

#include 
#define SLEN 32

// structure declarations
struct names_st
{
	char first[SLEN];
	char last[SLEN];
};

// typedefs
typedef struct names_st names;

// function prototypes
void get_names(names *);
void show_names(const names *);
char * s_gets(char * st, int n);





// 1.cpp -- names_st structure header file

// constants
#include 
#define SLEN 32

// structure declarations
struct names_st
{
	char first[SLEN];
	char last[SLEN];
};

// typedefs
typedef struct names_st names;

// function prototypes
void get_names(names *);
void show_names(const names *);
char * s_gets(char * st, int n);



//2.cpp

// useheader.c -- use the names_st structure
#include 
#include "2.h"
// remember to link with names_st.c

int main(void)
{
	names candidate;

	get_names(&candidate);
	printf("Let's welcome ");
	show_names(&candidate);
	printf(" to this program!\n");
	return 0;
}

 

6.编译运行

用vs2015 自己写一个头文件并使用的方法_第7张图片

ok,成功

 

你可能感兴趣的:(1)