#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main()
{
string str("some string!!!");
string::size_type space_cnt=0;
for(string::size_type ix=0;ix!=str.size();++ix)
cout<<toupper(str[ix]);
return 0;
}
输出结果:
可以看出输入结果为每一个转换后的字符的ASCII码。在查看了toupper()函数的声明,即 int __cdecl toupper(_In_ int _C),找出了问题的所在。toupper()函数的返回值是int类型。类似的,cctype中定义的函数的返回值都是int类型。