#include "stdafx.h"
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
class student
{
public:
void set_grate()
{
cout << "输入学生所在年级:" << endl;
cin >> grate;
}
void set_name()
{
cout << "输入学生姓名:" << endl;
cin >> name;
}
void set_ID()
{
cout << "输入学生学号:" << endl;
cin >> ID;
}
int get_grate()
{
return grate;
}
int get_ID()
{
return ID;
}
string get_name()
{
return name;
}
private:
int ID;
string name;
int grate;
};
int main()
{
student s[256];
int n = 0,i = 0;
cout << "请输入学生人数!" << endl;
cin >> n;
for (int i = 0; i<n; i++)
{
s[i].set_grate();
s[i].set_name();
s[i].set_ID();
}
ofstream ofs("d:\\a.txt");
if (!ofs)
{
cout << "open failed" << endl;
}
for (int i = 0; i<n; i++)
{
ofs << s[i].get_grate() << " " << s[i].get_name() << " " << s[i].get_ID() << " " << endl;
}
ofs << "年级 " << "姓名 " << "学号 " << endl;
cout << "年级 " << "姓名 " << "学号 " << endl;
ofs.close();
ifstream ifs("d:\\a.txt");
int grate, id;
string name;
if (ifs)
{
for (int i = 0; i<3; i++)
{
ifs >> grate >> name >> id;
cout << grate << " " << name << " " << id << " " << endl;
}
}
else
cout << "if failed" << endl;
ifs.close();
system("pause");
return 0;
}
10-02
08-02
06-15
06-15
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交