将文件poem.txt中的英文诗读出来,并显示在控制台上,要求将原文中的小写字母显示为对应的大写字母
// 假设没有中文
#include<iostream>
#include<fstream>
using namespace std;
int main() {
ifstream infile;
infile.open("poem.txt", ios::in);
infile.seekg(0, ios::beg);
while (!infile) {
cerr << "File could not be open" << endl;
abort();
}
char ch;
int t;
while (infile.get(ch)) {
t = (int)ch;
if (t >= 97 && t <= 122)
cout << (t - 32);
else
cout << ch;
}
infile.close();
}