我在 C++ 中编写了一个简单的函数,使用字符将字符串转换为所有小写字母并遍历字符串中的每个字符。有人能解释一下为什么当我在控制台窗口中运行这个程序时,如果函数从不引用 cout,除了我的原始输入之外,我还会得到一个输出。
#include <iostream>
#include <cctype>
#include <cstdlib>
using namespace std;
string makelower(string text)
{
int iter = 0;
char cha;
string newtext;
while (iter < text.length())
{
cha = text[iter];
cha = tolower(cha);
newtext+=cha;
iter++;
}
return(newtext);
}
int main()
{
string a;
cin>>a;
a = makelower(a);
cout<<a;
}