更新时间: 试题数量: 购买人数: 提供作者:

有效期: 个月

章节介绍: 共有个章节

收藏
搜索
题库预览
下面程序实现的功能:将某宿舍学生的学号、姓名和网络投票等信息存入二进制文件(vote.dat),也可以读取文件内容显示在屏幕上。请问:在红色下划线处应添加( )语句? #include<iostream> #include<fstream> #include<string> #include <iomanip> using namespace std; const int N = 4; class StuVote { public: void getVote() { cout << "(学号 姓名 票数):"; cin >> id >> name >> vote; } void showVote() { cout << setw(9) << id << setw(10) << name << setw(6) << vote << endl; } private: int id; char name[9]; int vote; }; class App { public: void run(); void inWriteData(); void readOutData(); private: StuVote stu; }; void App::inWriteData() { ofstream out("vote.dat", ios_base::binary); for (int i = 0; i < N; i++) { cout << "第" << i + 1 << "个学生数据"; stu.getVote(); out.write((char*)&stu, sizeof(stu)); }; out.close(); } void App::readOutData() { //此处是建立文件流对象,以二进制模式输入(vote.dat) ________________ if (in) { while (in.read((char*)&stu, sizeof(stu))) { stu.showVote(); } } else { cout << "Error" << endl; exit(-1); } in.close(); } void App::run() { int i; do { cout << "------------------------" << endl; cout << " 1:输入数据 2:输出数据 0:退出系统 " << endl; cout << "------------------------" << endl; cout << "您的选择 :"; cin >> i; switch (i) { case 1:inWriteData(); break; case 2:readOutData(); break; case 0:cout << "欢迎下次再来!" << endl; exit(0); }; } while (i != 1 || i != 2 || i != 0); } int main() { App app; app.run(); return 0; }