写一个类,并创建其对象,利用该对象调用类中的某个公有成员函数来输出该类某个私有数据成员的值
#include <iostream>
#include <Windows.h>
class Student
{
public:
Student (std::string n, int a) : name(n), age(a){
}
std::string name;
int age = 0;
void printInfo()
{
std::cout << "学生姓名:"<<name << std::endl;
std::cout << "学生年龄:"<<age << std::endl;
}
std::string getName(){
return name;
}
int getAge(){
return age;
}
};
int main()
{
SetConsoleOutputCP(CP_UTF8); //解决中文乱码
Student stu = Student("张三", 18);
stu.printInfo();
system("pause");
return 0;
}