怎么大小写都没进行转换?为什么这些函数都没被调用,要如何改正
c++吧
全部回复
仅看楼主
level 6
钱包芳 楼主
2015年05月13日 10点05分 1
level 6
// cctypes.cpp--use ctype.h library
#include <iostream>
#include <cctype> // prototypes for character functions
int main()
{
using namespace std;
cout << "Enter text for analysis, and type @"
" to terminate input.\n";
char ch;
int whitespace = 0;
int digits = 0;
int chars = 0;
int punct = 0;
int others = 0;
cin.get(ch); // get first character
while(ch != '@') // test for sentinel
{
if(islower(ch))
{
ch=toupper(ch);
chars++;
}
else if(isupper(ch))
{
ch=tolower(ch);
chars++;
}
else if(isspace(ch)) // is it a whitespace character?
whitespace++;
else if(isdigit(ch)) // is it a digit?
digits++;
else if(ispunct(ch)) // is it punctuation?
punct++;
else
others++;
cout<<ch;
cin.get(ch); // get next character
}
cout << chars << " letters, "
<< whitespace << " whitespace, "
<< digits << " digits, "
<< punct << " punctuations, "
<< others << " others.\n";
return 0;
}
2015年05月13日 11点05分 2
谢谢,这道例题我有认真看了,可是自己仿照着编还是不明白为什么最后小写可以输出大写,而大写还是输出大写
2015年05月13日 14点05分
level 6
钱包芳 楼主
谢谢,这道例题我有认真看了,可是自己仿照着编还是不明白为什么最后小写可以输出大写,而大写还是输出大写
2015年05月13日 14点05分 3
ch=toupper(ch),<cctype>的库函数 百度一下
2015年05月13日 15点05分
level 1
#include <iostream>
#include <cctype>
using namespace std;
int main()
{
char ch;
cout << "Please enter: \n";
cin.get(ch);
while (ch != '@')
{
if(islower(ch))
{
ch = toupper(ch);
cout << ch;
}
else if(isupper(ch))
{
ch = tolower(ch);
cout << ch;
}
else
{
cout << ch;
}
cin.get(ch); // if lack it will keep continue jJ3K ---- JjJjJj---
}
return 0;
}
2017年07月11日 07点07分 4
level 9
居然没报错?
2017年07月15日 09点07分 5
1