注册 登录
编程论坛 C++教室

如下程序如何在VisualC++中运行

chengxu2 发布于 2015-12-29 19:17, 1695 次点击

//student. h
#include<string>
using namespace std;
class student
{
public:
    void display();
private:
    int num;
    string name;
    char sex;
};
//student. cpp
#include<iostream>
#include"student.h"
void student::display()
{cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl;
}
//main.cpp
#include<iostream>
#include"student.h"
using namespace std;
int main()
{
    student stud;
    stud display();
    return 0;
}
3 回复
#2
chengxu22015-12-29 19:22
就是student.h头文件不知怎么弄?
#3
wp2319572015-12-30 09:55
刚开始弄时  不必要弄那么多点h文件 点cpp文件 全放一起就可
#4
诸葛欧阳2015-12-30 12:54
按你这个你需要建一个.h两个.cpp文件分别是student.h student.cpp main.cpp然后直接在mian.cpp中包含student.h就可以了,注意你的函数调用,成员函数要用.运算符
1