类声明和成员函数定义的分离
//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" //提示说这有错 student.h: No such file or directory,本萌新用的devc++,还望各位大佬解决,最好直接写代码,谢谢
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;
}