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

1.打开vs2015

2 新建项目

 点 确定, 然后,点下一步

完成

 

3.添加源文件项

添加

 

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

5.添加相关代码

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


// 2.h 

#include <string.h>
#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 <string.h>
#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 <stdio.h>
#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.编译运行

ok,成功

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值