第1个回答 2009-01-10
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
int main()
{
int n = 0;
cout << "学生人数: " << ends;
cin >> n;
ofstream of("Ko.txt");
if (!of)
{
cerr << "Con't not file error." << endl;
return -1;
}
int id;
string name;
for (int i = 0; i != n; ++i)
{
cout << "学号: " << ends;
cin >> id;
cout << "姓名: " << ends;
cin >> name;
of << id << ends;
of << name << endl;
}
of.close();
ifstream inf("Ko.txt");
if (!inf)
{
cerr << "Con't not file error." << endl;
return -1;
}
while (inf >> id >> name)
{
if (id % 2 != 0)
{
cout << id << ends
<< name << endl;
}
}
of.close();
return 0;
}
第2个回答 2009-01-10
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
int main()
{
int n = 0;
cout << "学生人数: " << ends;
cin >> n;
ofstream of("Ko.txt");
if (!of)
{
cerr << "Con't not file error." << endl;
return -1;
}
int id;
string name;
for (int i = 0; i != n; ++i)
{
cout << "学号: " << ends;
cin >> id;
cout << "姓名: " << ends;
cin >> name;
of << id << ends;
of << name << endl;
}
of.close();
ifstream inf("Ko.txt");
if (!inf)
{
cerr << "Con't not file error." << endl;
return -1;
}
while (inf >> id >> name)
{
if (id % 2 != 0)
{
cout << id << ends
<< name << endl;
}
}
of.close();
return 0;
}