我有一段代码要求用户输入,它是“字符串”类型,它是一个非常简单的过程,我希望使用 tolower() 函数转换用户输入的任何内容。它完全按照它应该做的那样做,但我似乎无法将它分配给同一个变量。请问有什么帮助吗?
#include <locale>
#include <string>
#include <iostream>
//maybe some other headers, but headers aren't the problem, so I am not going to list them all
while (nCommand == 0)
{
locale loc;
string sCommand;
cin >> sCommand;
for (int i = 0; i < sCommand.length(); ++i)
{
sCommand = tolower(sCommand[i],loc);
cout << sCommand;
}
例如,如果用户在 Help sCommand 中键入的是 h
如果用户输入 HELP 或 Help 或 HeLp,我希望它看起来如何
sCommand 无论哪种方式都应该是“帮助”