vs2005 创建c++项目

来源:互联网 发布:java单例和多例 编辑:程序博客网 时间:2024/06/16 07:21
原文地址:创建c++项目">vs2005 创建c++项目作者:Francis

例子:

建立项目名c1将会产生以下文件stdafx.h;c1.cpp;

如果要加入新的头文件head1.h;与新的.cpp文件head1.cpp;

可以将所要的头文件全放在stdafx.h中;

一个简单的例子可知各个文件的代码如下:

stdafx.h

// stdafx.h : 标准系统包含文件的包含文件,
// 或是经常使用但不常更改的
// 特定于项目的包含文件
//

#pragma once


#define WIN32_LEAN_AND_MEAN  // 从Windows 头中排除极少使用的资料
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include "head1.h"


// TODO: 在此处引用程序需要的其他头文件

c1.cpp:

// c1.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
 Student stud;
 stud.display ();
 return 0;
}
head1.h:

//定义了Student类
class Student
{public:
    voiddisplay();
 private:
 int num;
 char name[20];
 char sex;
};

 

head1.cpp:

#include "stdafx.h"
using namespacestd;//因为用到cout以及endl命令
void Student::display()
{
 cout<<"num:"<<num<<endl;
 cout<<"name:"<<name<<endl;
 cout<<"sex:"<<sex<<endl;
}