学生类输入输出姓名学号

2022/6/6 23:19:50

本文主要是介绍学生类输入输出姓名学号,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

一、建立一个学生类

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;
}

 



这篇关于学生类输入输出姓名学号的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程