gpt4 book ai didi

c++ - 如何将大写字母读成小写字母?

转载 作者:行者123 更新时间:2023-11-27 23:36:03 27 4
gpt4 key购买 nike

Chatbot 将读取他们的输入并根据输入进行回复,但小写和大写的读取并不相等。我一直没能找到如何让这段代码将大写字母读成小写字母的方法。我如何让它将输入识别为小写字母?

#include <iostream>
#include <cstring>
#include <locale>
#include <limits>
#include <cstdlib>

using namespace std;

int main

(int argc, char **argv)
{

string input;

cout << "Hello there" << endl;
{

for(;;)
{

std::cin >> input;

if (input == "hi")
cout << "hey what's up?" << endl;
if (input == "hey")
cout << "hey, what's up?" << endl;
if (input == "hello")
cout << "Hey, what's up?" << endl;
if (input == "how are you?")
cout << "I am good, how are you?" << endl;
if (input == "fine")
cout << "that's good" << endl;
if (input == "hru")
cout << "i am good, how are you?" << endl;
if (input == "good")
cout << "thats good" << endl;

}
}
}

最佳答案

通过在进行比较之前将所有内容都转换为小写。要轻松做到这一点,#include <cctype>并使用 tolower() 函数。

关于c++ - 如何将大写字母读成小写字母?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59123791/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com