您的位置:首页 > 其它

从一个文本文件读取正文,将其中的小写字母转化成大写字母,大写字母转换成小写字母,其他字符不变。

2012-07-04 10:52 429 查看
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
ifstream infile("txt");
if (!infile)
{
cerr << "Can't open file." << endl;
}

char ch;
while (infile.get(ch))
{
if (ch >= 'a' && ch <= 'z')
{
ch -= 32;
}
else if (ch >= 'A' && ch <= 'Z')
{
ch += 32;
}
cout << ch;
}
infile.close();
return 0;
}


python的实现

>>> "This Is Test".swapcase() #Œ大小写互换

'tHIS iS tEST'
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐