无法获得输入以产生响应(Chatbot)

时间:2019-11-27 01:18:17

标签: c++ chatbot

我希望代码回答问题或输入内容,但我不知道如何操作。我之前已解决此问题,但我丢失了文件和EXE,如何获得问题的答复?

我希望用户输入问题或对话,然后聊天机器人会做出响应。

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

using namespace std;

int main

(int argc, char **argv)
{

string input;

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

for(;;)
{

std::cin.
ignore(std::numeric_limits<std::streamsize>::max(), '\n');

这是输入内容,我无法回应。

if (input == "hi")
cout << "hey what's up?" << endl;
else;
if (input == "hey")
cout << "hey, what's up?" << endl;
else;
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;
if (input == "")
cout << "" << endl;
if (input == "")
cout << "" << endl;
if (input == "")
cout << "" << endl;
if (input == "")
cout << "" << endl;
if (input == "")
cout << "" << endl;
if (input == "")
cout << "" << endl;
        }
    }
}

完整代码:

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

using namespace std;

int main

(int argc, char **argv)
{

string input;

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

for(;;)
{

std::cin.
ignore(std::numeric_limits<std::streamsize>::max(), '\n');

if (input == "hi")
cout << "hey what's up?" << endl;
else;
if (input == "hey")
cout << "hey, what's up?" << endl;
else;
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;
if (input == "")
cout << "" << endl;
if (input == "")
cout << "" << endl;
if (input == "")
cout << "" << endl;
if (input == "")
cout << "" << endl;
if (input == "")
cout << "" << endl;
if (input == "")
cout << "" << endl;
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您决定使用ignore的原因是否特殊?如果您将整行替换为

std::cin >> input;

应该工作正常。

请注意。由于;,您有一些空的else语句,而并非所有的if语句都有else,因此程序会遍历多个。