#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'