C++ 程序:将二进制文件中的大写字母转换为小写字母
#include
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; }
// 读取s2.dat中的字符,将大写字母改为小写字母后写入d2.dat
while (fp1.read(&ch, sizeof(ch)))
{
if ((ch >= 'A') && (ch <= 'Z'))
{
ch = ch + 32;
}
fp2.write(&ch, sizeof(ch));
}
fp1.close();
fp2.close();
return 0;
}
原文地址: https://www.cveoy.top/t/topic/oj6b 著作权归作者所有。请勿转载和采集!