一、建立一个学生类

class student//创建一个学生类
{
public://公共访问权限
	string name;
	string ID;
};

二、完整代码

#define _CRT_SECURE_NOWARNINGS//宏定义,防止调用函数时报错
#include <iostream>
#include <string>
using namespace std;
class student//创建一个学生类
{
public://公共访问权限
	string name;
	string ID;
};
int main()
{
	student st;//给该类起名,创建具体对象(即为实例)
	cout << "输入学生姓名:" << endl;
	cin >> st.name;
	cout << "输入学生ID:" << endl;
	cin >> st.ID;
	cout << "学生姓名:" << st.name <<endl<< "学生ID:" << st.ID << endl;
	system("pause");//暂停输出的黑窗口,防止一闪而过
	return 0;
}