C++实现聊天机器人

​#include 
#include 
using namespace std;

int main() {
    string question;
    string answer;

    // Define question and answer list
    string questions[] = {"Hi", "How are you?", "What's your name?"};
    string answers[] = {"Hello", "I'm fine, thanks.", "My name is Chatbot."};

    // Get user input
    while (true) {
        cout << "Ask me a question: ";
        getline(cin, question);

        // Compare user input with questions
        if (question == questions[0]) {
            answer = answers[0];
        } else if (question == questions[1]) {
            answer = answers[1];
        } else if (question == questions[2]) {
            answer = answers[2];
        } else {
            answer = "I don't understand.";
        }

        // Give answer
        cout << answer << endl;
    }

    return 0;
}

你可能感兴趣的:(C++更多语法,c++,开发语言)