大家好,这里是国中之林!
❥前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到网站。有兴趣的可以点点进去看看←
问题:
解答:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;typedef struct _Donor
{string name;double money;
}Donor;int main()
{ifstream file;string filename;int count = 0;cout << "请输入文件名:";getline(cin, filename);file.open(filename);if (!file.is_open()){cout << "文件打开失败!" << endl;exit(EXIT_FAILURE);}bool empty = true;;file >> count;Donor* donors = new Donor[count];file.get();for (int i = 0; i < count; i++){getline(file, donors[i].name);file >> donors[i].money;file.get();}cout << "重要捐款人的信息如下:" << endl;for (int i = 0; i < count; i++){if (donors[i].money >= 10000){cout << donors[i].name << endl;empty = false;}}if (empty){cout << "NONE" << endl;}cout << "普通借款人信息如下:" << endl;for (int i = 0; i < count; i++){if (donors[i].money < 10000){cout << donors[i].name << endl;empty = false;}}if (empty){cout << "NONE" << endl;}return 0;
}
运行结果:
考查点:
- 文件的读入
注意:
- get()的用处