#include #include //头文件 using namespace std;

int main() { ifstream fp1('s1.txt'); //打开s1.txt文件,使用ifstream读取文件 ofstream fp2('d1.txt'); //打开d1.txt文件,使用ofstream写入文件 char ch; if (!fp1.is_open()) //判断文件是否成功打开 { cout<<'can not open s1.txt\n'; return 0; } if (!fp2.is_open()) { cout<<'can not open d1.txt\n'; return 0; } while(fp1.get(ch)) //使用get函数读取文件中每一个字符 { if((ch>='a')&&(ch<='z')) { ch=ch-32; //将小写字母转换为大写字母 } fp2.put(ch); //使用put函数将每个字符写入d1.txt文件中 } fp1.close(); //关闭文件 fp2.close(); return 0; }

C++ 文件操作:将文本文件中小写字母转换为大写字母

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

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