我不允许使用toupper()如何将字符串转换为大写C++
这些是我的函数,一个函数必须通过引用传递字符串。
void Uppercase(string x)
{
int y = 0;
while (y < x.length)
{
x[y] = x[y] - 32;
y++;
}
}
void uppercase(string &x)
{
int y = 0;
while (y < x.length)
{
x[y] = x[y] - 32;
y++;
}
我至少有正确的想法吗?
我得到这个错误,当我建立它....
错误5错误C2446: '<':无论从“无符号整型(__thiscall的std :: basic_string的,性病::分配器转换> :: * )(void)throw()const'to'int'c:\ users \ edwingomez \ documents \ visual studio 2013 \ projects \ homework \ homework \ homework6.cpp 18 1作业
32是一个幻数,应至少用一个常数代替。 – chris 2015-03-31 16:47:23
您需要检查字符是否在正确的范围'a' - 'z'中,并且第一个函数不会做任何事情,字符串在内部被修改,但结果是看不到的。 – NetVipeC 2015-03-31 16:47:53
你遗漏了括号:'x.length()'。 – molbdnilo 2015-03-31 16:59:03