完善程序如下:

#include #include using namespace std; int main() { char ch; ifstream fp1("s2.dat",ios_base::binary); if (!(fp1.is_open())) { cout<<"can not open s2.dat\n"; return 0; } ofstream fp2("d2.dat",ios_base::binary); if (!(fp2.is_open())) { cout<<"can not open d2.dat\n"; return 0; } while(fp1.read((char*)&ch,sizeof(ch))) { if((ch>='A')&&(ch<='Z')) { ch=ch+32; }
fp2.write((char*)&ch,sizeof(ch));
} fp1.close(); fp2.close(); return 0; }

注释:

  1. 读取二进制文件需要使用 read 函数,写入二进制文件需要使用 write 函数。

  2. 在循环中,先使用 read 函数读取一个字符到变量 ch 中,然后判断该字符是否为大写字母,如果是,则将其转换为小写字母,最后使用 write 函数将修改后的字符写入到另一个二进制文件中

完善程序:程序从二进制文件s2dat中读入所有字符到内存将其中的大写字母全改成小写字母然后输出到二进制文件d2dat中。#include iostream#include fstreamusing namespace std;int main char ch; ifstream fp1s2datios_basebinary; if !fp1is_open c

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

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