#include <iostream> using namespace std; class StInfo Begin//在此处声明StInfo类 End ********* ********* Begin *********| //在此处定义StInfo类
时间: 2024-03-30 19:31:36 浏览: 127
使用include <iostream>时一定要加using namespace std
#include <iostream>
using namespace std;
class StInfo {
public:
string name;
int age;
string major;
void displayInfo() {
cout << "Name: " << name << endl;
cout << "Age: " << age << endl;
cout << "Major: " << major << endl;
}
};
int main() {
StInfo student; // 创建一个StInfo类的对象
student.name = "John";
student.age = 20;
student.major = "Computer Science";
student.displayInfo(); // 调用StInfo类的displayInfo()函数显示学生信息
return 0;
}
阅读全文