改用C++函数
时间: 2023-07-11 21:05:33 浏览: 58
好的,下面是一个简单的C++函数示例:
```c++
#include <iostream>
#include <string>
using namespace std;
void chatbot(string message) {
if (message == "hello") {
cout << "Hi there!" << endl;
} else if (message == "how are you?") {
cout << "I'm doing great, thanks for asking!" << endl;
} else if (message == "what's your name?") {
cout << "My name is Chatbot. Nice to meet you!" << endl;
} else {
cout << "I'm sorry, I don't understand. Can you please rephrase?" << endl;
}
}
int main() {
string input;
while (true) {
cout << "You: ";
getline(cin, input);
chatbot(input);
}
return 0;
}
```
这个函数实现了一个简单的聊天机器人,每当用户输入一条消息时,它会根据消息内容进行相应的回复。您可以添加更多的if语句来增加聊天机器人的功能,也可以使用更复杂的算法和模型来实现更高级的聊天机器人。