Я все еще довольно новичок в C ++ и программировании, поэтому я мог бы просто упустить что-то большое здесь.
Я пытаюсь создать чат-бота для библиотеки, занимаюсь вопросами времени работы и т. Д.Я хочу, чтобы чат-робот мог подбирать ключевые слова на входе и затем вызывать нужную функцию, которая сможет вернуть им какой-то текст.
Например:
пользователь: во сколько библиотека открыта?// chatbot подбирает ключевое слово «open» и возвращает нужную функцию chatbot: библиотеки открываются между 6 и 5
Это не должно быть так сложно, как я нахожу, чтобы иметь возможность получить чат-ботасделать это.
Функция, с которой у меня проблемы:
std::string GetKeywords(){
std::string KQuery = GetQuery();
std::vector<std::string> keywords{"open", "opening", "times", "close", "closing", "shut"};
if(std::find(keywords.begin(), keywords.end(), KQuery) != keywords.end()){
std::cout << "Library is open when I say it is" << std::endl;
}
return 0;
};
Это возвращает ошибку памяти и является единственным местом в моем коде, которое вызывает проблему.
Весь мой код:
#include <iostream>
#include <string>
#include <vector>
#include "FinalProject.hpp"
//introducing funtions
void PrintIntro();
std::string GetQuery();
std::string RunScripts();
std::string GetKeywords();;
// introducing chatbot
RunScript ChatBot;
int main(){
PrintIntro();
GetQuery();
GetKeywords();
};
void PrintIntro(){
//printing introductory text to ask the user for input
std::cout << "Hi, I'm Librarius, I'm here to help you with University library queries" << std::endl;
std::cout << "I can help you with the following: \n Spaces to study \n Opening times \n Taking out books \n Returning books\n" << std:: endl;
std::cout << "Ask away!" << std::endl;
return;
};
std::string GetQuery(){
//getting input from the user
std::string Query = "";
std::getline(std::cin, Query);
if(Query.empty()){
//checking to see if the user hasnt entered anything
std::cout << "Hey! Why didnt you enter anything?! I don't want to waste my time!" << std::endl;
};
return Query;
};
std::string GetKeywords(){
std::string KQuery = GetQuery();
std::vector<std::string> keywords{"open", "opening", "times", "close", "closing", "shut"};
if(std::find(keywords.begin(), keywords.end(), KQuery) != keywords.end()){
std::cout << "Library is open when I say it is" << std::endl;
}
return 0;
};
//using the input got from the user to decide which script to run
//TODO analyse the users keywords and decide on a script to run
//TODO return an appropriate script
Спасибо за помощь!