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,成功