I am writing a chatbot and it's database is going to be contained in a .txt file.
Now i have this code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string line;
string uinput, resp;
char key = line[0];
ifstream file("t.txt");
cout<<": ";
getline(cin, line);
while(getline(file, line))
{
switch(key)
{
case 'i':
{
if(uinput == line)
{
continue;
}
}
case 'r':
resp = line;
break;
default:
continue;
break;
}
cout<<resp;
}
}
This code is suppose to read the filem line by line. And if the virst letter = i; It must check to see if the user's input match that line, else if the first letter = r and the previos line matched the user's input it must read that line into another string and then print it.
The problem is I dont really know how to do this...
So how is this going to be done? (Sample code would be appreciate)
Thanks...