最后,我找到了将小写转换为大写并确定字符串是字母还是数字代码的解决方案,如下所示:
#include <cctype>
#include <iostream>
using namespace std;
int main()
{
char ch;
cout<<"Enter a character: ";
gets(ch);
if ( isalpha ( ch ) ) {
if ( isupper ( ch ) ) {
ch = tolower ( ch );
cout<<"The lower case equivalent is "<< ch <<endl;
}
else {
ch = toupper ( ch );
cout<<"The upper case equivalent is "<< ch <<endl;
}
}
else
cout<<"The character is not a letter"<<endl;
cin.get();
}
如何改进上面的代码以获取字符串而不是单个字符?循环多次打印相同的语句。谢谢