有人可以解释为什么这个 C++ 中的短代码不会产生预期的输出。该代码应该以大写字母打印字符串。
#include <iostream>
#include <string>
using namespace std;
int main(){
string sample("hi, i like cats and dogs.");
cout << "small: " << sample << endl << "BIG : ";
for(char c: sample)
cout << toupper(c);
cout<<endl;
return 0;
}
上述程序的输出是:
small: hi, i like cats and dogs.
BIG : 72734432733276737569326765848332657868326879718346
但我期望:
small: hi, i like cats and dogs.
BIG : HI, I LIKE CATS AND DOGS.
我只用python编程过。