#include #include using namespace std;

int main() { char ch; ifstream ifs('s2.dat', ios_base::binary); if (!ifs.is_open()) { cout << 'Can not open s2.dat\n'; return 0; } ofstream ofs('d2.dat', ios_base::binary); if (!ofs.is_open()) { cout << 'Can not open d2.dat\n'; return 0; } ifs.get(ch); while (!ifs.eof()) { if (ch >= 'A' && ch <= 'Z') { ch += 32; // 大写字母转成小写字母 } ofs.put(ch); ifs.get(ch); } ifs.close(); ofs.close(); return 0; }

改动说明:

  1. 修正了文件流对象的命名规范,将 fp1 改成 ifs,将 fp2 改成 ofs,以符合命名规范。

  2. 在文件读取和写入前,增加了对文件是否成功打开的判断,如果打开失败,输出错误信息并返回 0。

  3. 将读取和写入文件的语句放在 while 循环中,以确保能够读取和写入整个文件。

  4. 将大写字母转成小写字母的代码加入到 while 循环中。

C++ 编程:将二进制文件中的大写字母转换为小写字母

原文地址: https://www.cveoy.top/t/topic/ok2W 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录